Serial MCU controlled relay/switch

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
HarpieC
Normal user
Posts: 22
Joined: 20 Mar 2016, 20:33

Re: Serial MCU controlled relay/switch

#351 Post by HarpieC » 31 Dec 2019, 12:52

Hello,

I just flashed the plugin on a Tuya wall dimmer (1 gang dimmer Board labeled with YDM_WIFI_SV4). Which was very painful because i had to cut the RX trace on the PCB to make it work. Sending command work but after every command the MQTT connection is lost.
Working (somehow) with tuya / dimmer#2
I`m using the homie controller. When I send commands via SYSTEM/cmd/set I get this

Code: Select all

10008544: SerSW : SetDim 255
10008559: SerSW : Dimmer d1:255
10008844: MQTT : Connection lost, state: Connection lost
10008869: MQTT : Connected to broker with client ID: ESPClient_80:7D:3A:3E:70:FA
10008872: Subscribed to: homie/Wanddimmer-01/+/+/set
10008975: SerSW : ReadState
Using The homie receiver plugin & trigger the command form there (aka via rules) works perfectly, so perhaps there is a timing problem in my homie controler plugin:


Here are the rules you need. Configure the homie receiver in (my case index 2) with an integer (1) and a boolean (2) parameter

Code: Select all

on Walldimmer#dimmer do
 ydim,%eventvalue1%
 let,1,%eventvalue1% // store to restore last dimmer state on switch=1
 HomieValueSet,2,1,%eventvalue1% // acknowledge dimmer
endon

on Walldimmer#switch do
 if [Walldimmer#switch]=0 
  relay,0,%eventvalue1%
 else
  ydim,[var#1]
  HomieValueSet,2,1,[var#1] // acknowledge dimmer optional
 endif
 HomieValueSet,2,2,%eventvalue1% // acknowledge switch
endon
But manual changes (button presses) are not read by the plugin or sent back to the broker. That`s a pity because I loose consistency between the homie state and the actual state. Homie has the ability to restore the last state after reboot and it works perfectly if the state is set via mqtt but if the state was done manually than this mechanism fails (restoring the last state on the mqtt broker)

I can live with it for now but if somebody has an idea to fix the update problem I would be thankful. Or anybody has a tip to flash the dimmer without cutting the RX trace. Now writing this I think I have to check if I repaired the RX line correctly.

Thank you for this plugin!

Chris

HarpieC
Normal user
Posts: 22
Joined: 20 Mar 2016, 20:33

Re: Serial MCU controlled relay/switch

#352 Post by HarpieC » 31 Dec 2019, 16:26

I checked TX and RX and it all seams fine. But still no readings from the tuya mcu.

HarpieC
Normal user
Posts: 22
Joined: 20 Mar 2016, 20:33

Re: Serial MCU controlled relay/switch

#353 Post by HarpieC » 09 Jan 2020, 17:49

Finally I got it working. The dimmer readings are still inconstant in example set to 185 read 85 or other values but the "relay" state (Relay0) works and the last state is restored after reboot or restart if the last command origin was the touch button too.
Here is the rules if somebody is interested:

Code: Select all

on Walldimmer#dimmer do
 ydim,%eventvalue1%
 let,1,%eventvalue1%
 HomieValueSet,2,1,%eventvalue1% // acknowledge dimmer
endon

on Walldimmer#switch do
 if [Walldimmer#switch]=0 
  relay,0,%eventvalue1%
 else
  ydim,[var#1]
  HomieValueSet,2,1,[var#1] // acknowledge dimmer state
 endif
 HomieValueSet,2,2,%eventvalue1% // acknowledge switch state
endon

on Dimmer#Relay0 do
 if [Dimmer#Relay0]!=[var#2] // only update on state change
  let,2,[Dimmer#Relay0]
  if [Dimmer#Relay0]=1
   HomieValueSet,2,4,true // acknowledge switch /set
  else
   HomieValueSet,2,4,false // acknowledge switch /set
  endif
 endif
endon

mix
Normal user
Posts: 1
Joined: 13 Jan 2020, 12:46

Re: Serial MCU controlled relay/switch

#354 Post by mix » 13 Jan 2020, 13:45

enesbcs wrote:
03 Aug 2019, 21:10
fiets wrote:
03 Aug 2019, 18:58
Can you give me an example?
Examples given at the first post viewtopic.php?p=16998#p16998
The following command switches the second relay on the panel, if it has a second relay and you set the correct number of relays on the plugin settings page:

Code: Select all

relay,1,1
The following command switches the first relay on the panel.

Code: Select all

relay,0,1
If it is not working, there are several other possibilities, from unstable power supply to not correct baud rates which render this device unusable. (for example: some units has misprogrammed MCU firmware which will not work without IPD setting, and some of them has absolutely no firmware...)
Quite by accident I came across the cause of the problem with LCTech Relay 4X (I was close to a nervous breakdown;)) why, despite the fact that the status of the relay in Hardware changes, the relay remains in an unchanging state. Pay attention to which of the LEDs on the relay board is lit after the EspEasy start. If BLUE is shining you will not work. The solution is to connect the module to the power supply while holding the Reset Switch (S2). Then the RED led will light up and the GREEN led will blink longer - then the module is really ready for work. It is enough to do it once or until the state changes.

In my LC Tech Relay 4X original AT Firmware in AP client mode the blue is lit, while the red one is in AP mode, which is misleading because it is usually not used in this mode.

Ps. maybe someone has already described a similar situation here and I haven't read (although I searched ... for 4 days) if it was so and now I repeat myself after someone, forgive me :)

Cosimo
Normal user
Posts: 2
Joined: 24 Jan 2020, 18:39

Re: Serial MCU controlled relay/switch

#355 Post by Cosimo » 24 Jan 2020, 18:42

Hello.
I don't know how to declare my lctech 4ch in Hassio. I wrote this in the configuration.yaml mo but it doesn't work what am I wrong?

- platform: mqtt
name: "LCtech"
command_topic: "cmnd/lctech/Relay0/power"
state_topic: "stat/lctech/Relay0/POWER"
# availability_topic: "tele/lctech/LWT"
qos: 1
payload_on: "relay,0,1 "
payload_off: "relay,0,0 "
payload_available: "Online"
payload_not_available: "Offline"
retain: false

User avatar
enesbcs
Normal user
Posts: 450
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#356 Post by enesbcs » 24 Jan 2020, 18:49

Cosimo wrote:
24 Jan 2020, 18:42
I don't know how to declare my lctech 4ch in Hassio. I wrote this in the configuration.yaml mo but it doesn't work what am I wrong?

- platform: mqtt
name: "LCtech"
command_topic: "cmnd/lctech/Relay0/power"
state_topic: "stat/lctech/Relay0/POWER"
I do not know neither HA nor Hassio. Command topic is "<MQTT subscribe template>/cmd" in ESPEasy so i guess it is "LCtech/cmd" for you.
State topic may be "LCtech/Relay0/POWER".. depends on your device and value names. I am a Domoticz only user.

Cosimo
Normal user
Posts: 2
Joined: 24 Jan 2020, 18:39

Re: Serial MCU controlled relay/switch

#357 Post by Cosimo » 25 Jan 2020, 23:59

- platform: mqtt
name: lctech
command_topic: "lctech/cmd"
state_topic: "lctech/Relay0/POWER"
payload_on: "relay,0,1"
payload_off: "relay,0,0"


Not work ,my friend....WHY???

User avatar
enesbcs
Normal user
Posts: 450
Joined: 18 Jun 2017, 11:02
Location: Békéscsaba, Hungary
Contact:

Re: Serial MCU controlled relay/switch

#358 Post by enesbcs » 26 Jan 2020, 09:53

Cosimo wrote:
25 Jan 2020, 23:59
- platform: mqtt

Not work ,my friend....WHY???
Maybe you did not add the necessary mqtt controller to espeasy.
Mosquitto_pub and Mosquitto_sub is a great tool in case of mqtt debuggin:
http://www.steves-internet-guide.com/mo ... b-clients/

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests