Tuya zigbee switch advanced configuration

Hello all,
I am a beginner to HA. I used before Tuya app (AKA Smart life) with different devices and recently I decided to move to HA.
Now I am using a Sonoff P hub with all my old Tuya switches via Zigbee2MQTT and Mosquito (installed on a Synology virtual machine). Everything works as expected except one thing: on tuya app I had the option to configure a switch to automatically turn of after a specific number of seconds. Like every time I tunr on a switch it will automatically turn off in 5 seconds. This was somehow hardcoded in the switch. I have tried to do the same in HA with no success.
I have found this topic: TuYa WHD02 control via MQTT | Zigbee2MQTT
but It does not work . When I use the on/off command works perfectly. When I use just the ā€œon_timeā€ I get the "2024-03-10 20:19:41Invalid message ā€˜nullā€™, skippingā€¦: message. When I use both ā€œon_timeā€: 5, ā€œoff_wait_timeā€: 5 I do not get any error but is not working neigher.

Anyone can help?
My device is

Wall switch module (WHD02), Firmware: 0122052017
Connected via [Zigbee2MQTT Bridge]

Hub: SONOFF Zigbee 3.0 USB Dongle Plus, ZBDongle-P TI CC2652P + CP2102(N)

NAS: Synology DSM 7.1.1-42962 Update 6,

HA Core 2024.3.0; Supervisor 2024.02.1; Operating System 12.0; Frontend 0240306.0;

Please bear with me - I am new to this. Have no idea how to debug, logs etc but eager to learn.
Thanks in advance.

Step 1. Read this

Step 2. If on with timed off isnā€™t already exposed in your device specific settings page in Z2MQTT, then you can set it using an mqtt message

Thanks for helping me.
Please bear with me. I do not think on with timed off is exposed.
My device specific settings looks like this:


In order to try the ā€œon_timeā€ parameter I had to go to developer/services and to publish using MQTT service the payload. And it worked fine for {ā€œstateā€ : ā€œONā€} and {ā€œstateā€ : ā€œOFFā€} but didnā€™t worked for {ā€œstateā€ : ā€œONā€, ā€œon_timeā€: 5, } (got the" Invalid message ā€˜nullā€™, skippingā€¦" message) nor for {ā€œstateā€ : ā€œONā€, ā€œon_timeā€: 5, ā€œoff_wait_timeā€: 2}. For this last one I get no error but the switch do not react most of the time (some times turns on after a random delay).
Thanks,

You can do it with a HA automation

Something like

- id: '1565803925029'
  alias: turn switch on after 5 seconds
  trigger:
  - entity_id: switch.immergas
    for: 00:00:05
    platform: state
    to: 'on'
  action:
  - data:
      entity_id: switch.immergas
    service: switch.turn_off

I thought about this and will work for most of the time but not always.
This switch controls a 240v relay. The relay works like this (I am sure there is a technical name for this type of relay but I do not know it):

switch is on => 240v goes in the relay => relay close a circuit and sends 240V to device.
switch is off =>0 goes to relay => relay keeps the circuit closed and still 240V to device.
switch is on again => 240v goes to relay => relay opens circuit and 0V goes to device.
switch is off => 0 goes to relay => relay keeps circuit open and 0V to device.

The reason why the switch should go off after after a few seconds is that you never want to have the relay under 240v for a long time.

I control the switch from HA (where an automation as you suggested will work) as well as from a wall switch. I can still make the automation work even if I use the wall switch. The only exception would be when the HA/server/computer/power are down. In tis case the automation will not work and the relay will stay under load - which I am trying to avoid.

I know for sure the switch has this parameter because I use to control it this way with Tuya app and it was working as intended both with app and with wall switch (app/server offline).

Thereā€™s an extra comma & space at the end. Thatā€™s why youā€™re getting invalid message.
Try this:
{ā€œstateā€ : ā€œONā€, ā€œon_timeā€: 5}

PS - your device might not actually be recognised as a WHD02 model. Could you post screenshots of the about, exposes & settings page for it?

1 Like

It was a typo in my above text. I used to publish the correct command and getting the ā€˜nullā€™ skipping error.
Here are the screenshots you requested:





Well, thereā€™s your problem. Its Zigbee Model is recognised as a TS001. (see edit below)
There are multiple similar issues in Z2MQTT github because Tuya keeps changing the last few letters in the Zigbee Manufacturer.

Now hereā€™s the weird part - your exact Model (_TZ3000_skueekg3) was mentioned here and the fix for that was released sometime last December.

Which brings me to my next question - how long has it been since you updated Z2MQTT?

EDIT: Ok, seems like I misread the fix - it was done to change the model, not the Zigbee Model.
Iā€™d raise an issue on Z2MQTT github to check why your device doesnā€™t like the on_time message

PS - I spotted your other thread and Iā€™m fairly convinced you just wired up your switch/pump incorrectly, or at least in a non-standard way.
Just follow the advice in the other thread and post up some wiring diagrams there, and once you sort that out, you wonā€™t need the on_time

My other post you are talking about is a different issue. Different hardware - nothing to do with this issue. The wiring is correct - itā€™s just me having difficulties explaining the situation. The pump is not controlled by me. It is already wired to a PCB and starts/stops without my input. All I want to do is HA showing if the pump is on/off. I do not need/want to control it. I cannot interfere with the PCB. All I was able to do was to find the L and N 240V wires that run from PCB to the pump and to connect the socketā€™s prongs to this wires. The socket itself does not feed power to any device, the pump is connected in parallel. The socket is set to turn ON after power loss.
This was working fine with Tuya Smart Life - socket shows ON when the pump is running and UNAVAILABLE/OFFLINE when the pump is off (I think Tuya (or maybe the Tuya hub) periodically pings the device and if no answer it marks is as unavailable). HA does not do that (or maybe the SONOFF hub does not do this). When the socket has no power HA still shows it as ON.
At first I was very happy with the solution Zenia proposed (with the power monitoring). Then I realized it is exactly the same thing like I did. The plug will show 44W power consumption when the pump is ON but when the pump is OFF the plug will go OFFLINE immediately. HA will still display 44W. It will wait for the plug to report and never ask for update.

Meanwhile I think I found a good solution for this problem. It require and additional permanent L (not from PCB) which I can easily provide. Then I need to replace the plug with a Zigbee switch module - like this one .

I will connect the wire that feeds L to the pump to S1.I will feed the pump from L1. The switch module will feed the pump when the PCB injects 240 into the circuit and accurately display when the pump is on or off.

Now back to the main issue - the on_time.
I have 2 more remarks about my issue:
I think that the on_time is a parameter you set in the switch. Once you do that you do not need to send it with every ON command. For example when you use the wall switch the module remembers the on_time an reacts accordingly.
Second remark: I have noticed some weid commands issued by HA to this device.
Every 3-4 minutes the MQTT logs shows:

<small>2024-03-13 22:40:13</small>`MQTT publish: topic 'zigbee2mqtt/Immergas', payload '{"linkquality":15,"power_on_behavior":"off","state":"OFF","switch_type":"toggle"}'`

Info <small>2024-03-13 22:46:55</small>`MQTT publish: topic 'zigbee2mqtt/Immergas', payload '{"action":"off","linkquality":18,"power_on_behavior":"off","state":"OFF","switch_type":"toggle"}'`

Info <small>2024-03-13 22:46:55</small>`MQTT publish: topic 'zigbee2mqtt/Immergas', payload '{"action":"","linkquality":18,"power_on_behavior":"off","state":"OFF","switch_type":"toggle"}'`

Info <small>2024-03-13 22:46:55</small>`MQTT publish: topic 'zigbee2mqtt/Immergas/action', payload 'off'`

Info <small>2024-03-13 22:56:03</small>`MQTT publish: topic 'zigbee2mqtt/Immergas', payload '{"linkquality":12,"power_on_behavior":"off","state":"OFF","switch_type":"toggle"}'`

Info <small>2024-03-13 22:59:14</small>`MQTT publish: topic 'zigbee2mqtt/Senzor Birou', payload '{"battery":100,"humidity":30.08,"linkquality":150,"temperature":25.82,"voltage":3000}'`

Info <small>2024-03-13 22:59:14</small>`MQTT publish: topic 'zigbee2mqtt/Senzor Birou', payload '{"battery":100,"humidity":30.06,"linkquality":150,"temperature":25.82,"voltage":3000}'`

Info <small>2024-03-13 23:03:33</small>`MQTT publish: topic 'zigbee2mqtt/Immergas', payload '{"linkquality":18,"power_on_behavior":"off","state":"OFF","switch_type":"toggle"}'`

Info <small>2024-03-13 23:03:33</small>`MQTT publish: topic 'zigbee2mqtt/Immergas', payload '{"linkquality":18,"power_on_behavior":"off","state":"OFF","switch_type":"toggle"}'`

Info <small>2024-03-13 23:16:55</small>`MQTT publish: topic 'zigbee2mqtt/Immergas', payload '{"action":"off","linkquality":15,"power_on_behavior":"off","state":"OFF","switch_type":"toggle"}'`

Info <small>2024-03-13 23:16:55</small>`MQTT publish: topic 'zigbee2mqtt/Immergas', payload '{"action":"","linkquality":15,"power_on_behavior":"off","state":"OFF","switch_type":"toggle"}'`

Info <small>2024-03-13 23:16:55</small>`MQTT publish: topic 'zigbee2mqtt/Immergas/action', payload 'off'`

Is this normal?

I realized I didnā€™t thank you for helping me. I appreciate it a lot.

Thatā€™s what I thought too, but the documentation says otherwise.

Those seem to be normal reporting messages. Check the Reporting tab in your device settings in Z2MQTT and see if the frequency matches.
That last message for the /action topic is because you have enabled state action (last screenshot you sent from your settings page).
The others with action " " are normal because Z2MQTT immediately publishes an empty action after each actual action.
What is a bit worrying is that action ā€œoffā€ shouldnā€™t be published by itself. Your switch might be disconnecting and sending that on reconnect due to the power on behaviour setting (off).

My best suggestion at this point is to force remove & delete the switch from Z2MQTT & start from scratch using the default settings.
If that doesnā€™t get you anywhere, Iā€™d post a bug in Z2MQTT GitHub regarding the on_time.

Did you set the availability ?

And I agree with ShadowFist, try deleting it from Zigbee2MQTT and re-pair it.

When you mean set availability you refer to this?

I would need to make the plug report something every minute and in case it does not HA shoud mark the device as unavailable/ofline/off. Any of those will do the trick for me.

1 Like

Ok, using you ā€œavailabilityā€ suggestion I managed to make HA ping the device and return a warning message every 5 minutes when de device is not reachable.
image

How can I make HA automatically change the state of the device base on this? It still shows device is ON.


Or how can I make another device/helper with a ON state when plug is available and off when plug is not reachable?

I have re-pair it - no changes.
I have also flashed the coordinator to last firmware (20030507) - still no change.
I have posted the problem/bug here:

One more thing:
ā€œā€œThose seem to be normal reporting messages. Check the Reporting tab in your device settings in Z2MQTT and see if the frequency matches.ā€ā€
This is the only sensor reporting. All 5 others except for the wireless temperature sensor are never reporting. And the Reporting setting intervel does not match, this switch is reporting at random intervals (between 3 and 10 minutes)ā€¦

Letā€™s see how it goes.