Giter VIP home page Giter VIP logo

esphome-lctech-4chanel-modules's Introduction

Abstract

ESPHome configuration to drive LC-Technology relay modules. Tested on a 12V 4 channel version with nuvoton MCU. See detailed writeup of this project in my blog:

https://ncrmnt.org/?p=3333

Running & flashing

esphome xxx.yaml run

Configs

This repository contains 2 sample configs

  • gatekeeper.yaml

A config I used to drive Nice Flor-S remote control buttons.

  • relay-simple.yaml

A config that just exposes all relays for your fun.

  • relay.yaml

Same as the above, but with LEDs and buttons. Needs alternative nuvoton firmware

nuvoton firmware.

Stock firmware only supports relay control. I've also created an alternative firmware for nuvoton MCU that exposes three LEDs with PWM (RGB) and reports button states. You'll need nuvoton's ISP and a Windows box (or a VM) to flash it. I used linux to develop the firmware and a windows box to flash it.

Just grab the firmware.hex from here: https://github.com/nekromant/lctech-relay-altfw

Legal stuff

Copyright © 2019 Andrew 'Necromant' Andrianov [email protected] This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the COPYING file for more details.

esphome-lctech-4chanel-modules's People

Contributors

nekromant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

esphome-lctech-4chanel-modules's Issues

Support for x2 relays board

Hi,

I have a lot of lctech relays x2 boards with nuvoton 76e003 mcu.... Programmed with the .hex provided here but pinout is totally different for the x4 relays version.

Can you please tell me how to compile the source code? Tried with platformio but can't find the board, tried with keil but will put some errors on compiling....

Please help me, thanks in advance!!!

Error 2022

Thank you so much for your project! I would really like to use it, but I'm not good at programming, when I try to build, I get this:

In file included from src/main.cpp:49:
src/lccomponent.h: In member function 'virtual void LCButtons::setup()':
src/lccomponent.h:17:5: error: 'setTimeout' was not declared in this scope; did you mean 'set_timeout'?
17 | setTimeout(150);
| ^~~~~~~~~~
| set_timeout
src/lccomponent.h: In member function 'void LCButtons::update_button(uint8_t)':
src/lccomponent.h:28:15: error: 'readBytesUntil' was not declared in this scope
28 | int ret = readBytesUntil('\n', tmp, 8);
| ^~~~~~~~~~~~~~
Compiling .pioenvs/relay-x4/lib988/ESP8266WiFi/WiFiClientSecureBearSSL.cpp.o
Compiling .pioenvs/relay-x4/lib988/ESP8266WiFi/WiFiServer.cpp.o
*** [.pioenvs/relay-x4/src/main.cpp.o] Error 1
========================= [FAILED] Took 52.41 seconds =========================

What I use.
user@orangepipcplus:~$ esphome version
Version: 2022.5.1

|-- <ESPAsyncTCP-esphome> 1.2.3
|-- <ESPAsyncWebServer-esphome> 2.1.0
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|-- <noise-c> 0.1.4
|   |-- <libsodium> 1.10018.1
|-- <ArduinoJson> 6.18.5

errors compiling + not working

thanks for your work!

i get these errors when i try to run it:

In file included from src/main.cpp:18:0:
src/lccomponent.h:3:25: fatal error: esphome/log.h: No such file or directory
 #include "esphome/log.h"
                         ^
compilation terminated.
*** [.pioenvs/klingelknopf/src/main.cpp.o] Error 1

then i change the include in lccomponent.h to #include "esphome/core/log.h". but that leads to these errors:

In file included from src/main.cpp:18:0:
src/lccomponent.h:15:3: error: 'binary_sensor' does not name a type
   binary_sensor::BinarySensor buttons[2];
   ^
src/lccomponent.h: In member function 'void LCButtons::update_button(uint8_t)':
src/lccomponent.h:33:5: error: 'buttons' was not declared in this scope
     buttons[button - 1].publish_state(!value);
     ^
src/lccomponent.h: At global scope:
src/lccomponent.h:43:67: error: 'output' has not been declared
 class LCFloatOutput : public Component, public UARTDevice, public output::FloatOutput {
                                                                   ^
src/lccomponent.h:43:75: error: expected '{' before 'FloatOutput'
 class LCFloatOutput : public Component, public UARTDevice, public output::FloatOutput {
                                                                           ^
src/lccomponent.h:43:87: error: invalid type in declaration before '{' token
 class LCFloatOutput : public Component, public UARTDevice, public output::FloatOutput {
                                                                                       ^
src/lccomponent.h:44:2: error: expected primary-expression before 'public'
  public:
  ^
src/lccomponent.h:44:2: error: expected '}' before 'public'
src/lccomponent.h:44:2: error: expected ',' or ';' before 'public'
src/lccomponent.h:49:31: error: expected ')' before '*' token
   LCFloatOutput(UARTComponent *parent, const char prefix)
                               ^
src/lccomponent.h:54:16: error: virt-specifiers in 'setup' not allowed outside a class definition
   void setup() override {
                ^
src/lccomponent.h:57:33: error: virt-specifiers in 'write_state' not allowed outside a class definition
   void write_state(float state) override {
                                 ^
src/lccomponent.h: In function 'void write_state(float)':
src/lccomponent.h:59:26: error: invalid use of 'this' in non-member function
     LCRelay::send_packet(this, pre, v);
                          ^
src/lccomponent.h:59:32: error: 'pre' was not declared in this scope
     LCRelay::send_packet(this, pre, v);
                                ^
src/lccomponent.h: At global scope:
src/lccomponent.h:61:1: error: expected declaration before '}' token
 };
 ^

which i can circumvent via not including lccomponent.h.

However i still dont get the switch to work :(

This is my config:

esphome:
  name: yolo
  platform: ESP8266
  board: esp01_1m
  includes:
    - lcrelay.h
#    - lccomponent.h

uart:
  id: uart0
  baud_rate: 19200
  tx_pin: GPIO1
  rx_pin: GPIO3

switch:
  - platform: gpio
    name: "Gong_LED"
    restore_mode: "ALWAYS_OFF"
    pin:
      number: 1
      inverted: True
  - platform: custom
    lambda: |-
      auto r1 = new LCRelay(id(uart0), 1);
      App.register_component(r1);
      return {r1};
    switches:
      - name: "relay"
        id: relay1

wifi:
  ssid: 'yolo'
  password: 'yolo'

# dont mess with the relay
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  password: 'yolo'

ota:
  password: 'yolo'

I also suspect that it should somehow be possible to run this w/o extra C code, but i also did not get that to run :/

  - platform: template
    id: relay_1
    name: relay
    turn_on_action:
      - uart.write: [0xA0, 0x01, 0x01, 0xA2]
    turn_off_action:
      - uart.write: [0xA0, 0x01, 0x00, 0xA1]
    optimistic: true

# another try...

  - platform: uart
    name: "UART A1"
    data: [0xA0, 0x01, 0x00, 0xA1]
  - platform: uart
    name: "UART A2"
    data: [0xA0, 0x01, 0x01, 0xA2]

Ошибка при компиляции

Пробую компилировать в epshome пишет ошибку
`INFO Reading configuration /config/esphome/gatekeeper.yaml...
INFO Detected timezone 'MSK' with UTC offset 3
Failed config

uart:

  • [source /config/esphome/gatekeeper.yaml:30]

    ID 'uart' conflicts with the name of an esphome integration, please use another ID name.
    id: uart [source /config/esphome/gatekeeper.yaml:30]
    baud_rate: 115200
    tx_pin: GPIO1
    rx_pin: GPIO3`

compiling error with hassio ESPHome

I have created LCRelay.h and however I am getting an error compiling fw.
Could you point me out what is wring? thansk!

Compiling /data/r01/.pioenvs/r01/src/main.cpp.o
src/main.cpp:118:3: warning: multi-line comment [-Wcomment]
//   lambda: !lambda "auto r1 = new LCRelay(id(uart1), 1);\nauto r2 = new LCRelay(id(uart1),\
^
In file included from src/main.cpp:19:0:
src/lcrelay.h:23:52: error: expected class-name before ',' token
class LCRelay : public Component, public UARTDevice, public switch_::Switch {
^
src/lcrelay.h:27:27: error: expected ')' before '*' token
LCRelay(UARTComponent *parent, int relay): UARTDevice(parent) {
^
src/lcrelay.h: In member function 'virtual void LCRelay::write_state(bool)':
src/lcrelay.h:43:11: error: 'class LCRelay' has no member named 'write_array'
this->write_array(msg, sizeof(msg));
^
src/lcrelay.h:44:11: error: 'class LCRelay' has no member named 'write_array'
this->write_array(msg, sizeof(msg));
^
src/main.cpp: In lambda function:
src/main.cpp:137:37: error: no matching function for call to 'LCRelay::LCRelay(esphome::uart::UARTComponent*&, int)'
auto r1 = new LCRelay(uart1, 1);
^
src/main.cpp:137:37: note: candidates are:
In file included from src/main.cpp:19:0:
src/lcrelay.h:23:7: note: LCRelay::LCRelay()
class LCRelay : public Component, public UARTDevice, public switch_::Switch {
^
src/lcrelay.h:23:7: note:   candidate expects 0 arguments, 2 provided
src/lcrelay.h:23:7: note: LCRelay::LCRelay(const LCRelay&)
src/lcrelay.h:23:7: note:   candidate expects 1 argument, 2 provided
src/lcrelay.h:23:7: note: LCRelay::LCRelay(LCRelay&&)
src/lcrelay.h:23:7: note:   candidate expects 1 argument, 2 provided
src/main.cpp:138:37: error: no matching function for call to 'LCRelay::LCRelay(esphome::uart::UARTComponent*&, int)'
auto r2 = new LCRelay(uart1, 2);
^
src/main.cpp:138:37: note: candidates are:
In file included from src/main.cpp:19:0:
src/lcrelay.h:23:7: note: LCRelay::LCRelay()
class LCRelay : public Component, public UARTDevice, public switch_::Switch {
^
src/lcrelay.h:23:7: note:   candidate expects 0 arguments, 2 provided
src/lcrelay.h:23:7: note: LCRelay::LCRelay(const LCRelay&)
src/lcrelay.h:23:7: note:   candidate expects 1 argument, 2 provided
src/lcrelay.h:23:7: note: LCRelay::LCRelay(LCRelay&&)
src/lcrelay.h:23:7: note:   candidate expects 1 argument, 2 provided
src/main.cpp:139:37: error: no matching function for call to 'LCRelay::LCRelay(esphome::uart::UARTComponent*&, int)'
auto r3 = new LCRelay(uart1, 3);
^
src/main.cpp:139:37: note: candidates are:
In file included from src/main.cpp:19:0:
src/lcrelay.h:23:7: note: LCRelay::LCRelay()
class LCRelay : public Component, public UARTDevice, public switch_::Switch {
^
src/lcrelay.h:23:7: note:   candidate expects 0 arguments, 2 provided
src/lcrelay.h:23:7: note: LCRelay::LCRelay(const LCRelay&)
src/lcrelay.h:23:7: note:   candidate expects 1 argument, 2 provided
src/lcrelay.h:23:7: note: LCRelay::LCRelay(LCRelay&&)
src/lcrelay.h:23:7: note:   candidate expects 1 argument, 2 provided
src/main.cpp:140:37: error: no matching function for call to 'LCRelay::LCRelay(esphome::uart::UARTComponent*&, int)'
auto r4 = new LCRelay(uart1, 4);
^
src/main.cpp:140:37: note: candidates are:
In file included from src/main.cpp:19:0:
src/lcrelay.h:23:7: note: LCRelay::LCRelay()
class LCRelay : public Component, public UARTDevice, public switch_::Switch {
^
src/lcrelay.h:23:7: note:   candidate expects 0 arguments, 2 provided
src/lcrelay.h:23:7: note: LCRelay::LCRelay(const LCRelay&)
src/lcrelay.h:23:7: note:   candidate expects 1 argument, 2 provided
src/lcrelay.h:23:7: note: LCRelay::LCRelay(LCRelay&&)
src/lcrelay.h:23:7: note:   candidate expects 1 argument, 2 provided
src/main.cpp:145:29: error: could not convert '{r1, r2, r3, r4}' from '<brace-enclosed initializer list>' to 'std::vector<esphome::switch_::Switch*>'
return {r1, r2, r3, r4};
^
src/main.cpp:146:3: warning: control reaches end of non-void function [-Wreturn-type]
});
^
*** [/data/r01/.pioenvs/r01/src/main.cpp.o] Error 1

error

src/main.cpp:219:3: warning: multi-line comment [-Wcomment]
// lambda: !lambda "auto r1 = new LCRelay(id(uart0), 1);\nauto r2 = new LCRelay(id(uart0),
^
Compiling /data/4channel/.pioenvs/4channel/lib4d9/ESP8266WiFi/ESP8266WiFiSTA.cpp.o
Compiling /data/4channel/.pioenvs/4channel/lib4d9/ESP8266WiFi/ESP8266WiFiScan.cpp.o
In file included from src/main.cpp:29:0:
src/lccomponent.h:14:3: error: 'binary_sensor' does not name a type
binary_sensor::BinarySensor buttons[2];
^
src/lccomponent.h: In member function 'void LCButtons::update_button(uint8_t)':
src/lccomponent.h:32:5: error: 'buttons' was not declared in this scope
buttons[button - 1].publish_state(!value);
^
src/lccomponent.h: At global scope:
src/lccomponent.h:42:67: error: 'output' has not been declared
class LCFloatOutput : public Component, public UARTDevice, public output::FloatOutput {
^
src/lccomponent.h:42:75: error: expected '{' before 'FloatOutput'
class LCFloatOutput : public Component, public UARTDevice, public output::FloatOutput {
^
src/lccomponent.h:42:87: error: invalid type in declaration before '{' token
class LCFloatOutput : public Component, public UARTDevice, public output::FloatOutput {
^
src/lccomponent.h:43:2: error: expected primary-expression before 'public'
public:
^
src/lccomponent.h:43:2: error: expected '}' before 'public'
src/lccomponent.h:43:2: error: expected ',' or ';' before 'public'
src/lccomponent.h:48:31: error: expected ')' before '*' token
LCFloatOutput(UARTComponent *parent, const char prefix)
^
src/lccomponent.h:53:16: error: virt-specifiers in 'setup' not allowed outside a class definition
void setup() override {
^
src/lccomponent.h:56:33: error: virt-specifiers in 'write_state' not allowed outside a class definition
void write_state(float state) override {
^
src/lccomponent.h: In function 'void write_state(float)':
src/lccomponent.h:58:26: error: invalid use of 'this' in non-member function
LCRelay::send_packet(this, pre, v);
^
src/lccomponent.h:58:32: error: 'pre' was not declared in this scope
LCRelay::send_packet(this, pre, v);
^
src/lccomponent.h: At global scope:
src/lccomponent.h:60:1: error: expected declaration before '}' token
};
^
*** [/data/4channel/.pioenvs/4channel/src/main.cpp.o] Error 1

Wrong baud rate?

First at all, thanks for publishing your research about this board.

I tested the simple-relay.yaml but it did not worked with my board.

Then I re-read your blog, and compared the yaml in the post with the simple-relay.yaml in github. I noticed in your blog baud_rate was 115200. When I changed it in simple-relay.yaml and uploaded the binary, all the relays clicked!

I do not know if my board is a different batch, but on/off is reversed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.