Single phase Din rail Smart Switch with Energy monitoring zmai-90

all integrated in home assistant thanks to your great master job

I had already flashed it already several months ago with tuya converts

1 Like

Bottom line, on my device with tuya firmware 1.0.6 originally in the device I was able to successfully flash with tuya-convert. You will need to put Tasmota 7.1.1.2 firmware image (or later) in your tuya-convert/files, or use the existing one and OTA upgrade later.

hi,im getting this on the log:
Error parsing value: ‘value_json’ is undefined (value: ON, template: {{ value_json[“POWER”] }})
Error parsing value: ‘value_json’ is undefined (value: OFF, template: {{ value_json[“POWER”] }})

Got it, you need to replace:

state_topic: 'stat/general-meter-switch/POWER'

with:

state_topic: 'stat/general-meter-switch/RESULT'

Slight mistake when I copied the topic names. You likely were having the state out of sync when starting Hass.io.

Cheers

1 Like

Thanks again :+1:

1 Like

You are the best!
Thanks for sharing.

1 Like

Hi all, just an update on the DIN rail Tuya ZMAi-90 meter/switch: I have updated the documentation with the simplified procedure for flashing via serial port:


2. Using the serial cable:
temporarily solder a wire betwen the RSTn pin (the point between R30 and C20, as shown in the image below) and GND. This will keep the V9821 MCU from booting up and interfere with the communication on the ESP UART;
temporarily solder a wire betwen the TYWE3S module (where the ESP8266 chip is) GPIO0 pin and GND. This will put the ESP chip in programming mode;
connect TX, RX and GND to your USB-serial bridge. Make sure it is set for 3.3 Volts (5 Volts TTL will fry the chip);
provide 5 Volts and GND to the pins in the “J-V” connector, as shown in the picture:

using esptool or similar, flash the chip, making sure the flash size is forced to 1MB:

$ esptool.py --port COM3 --baud 74880 --after no_reset write_flash --flash_size 1MB --flash_mode dio 0x00000 tasmota.bin --erase-all

remove the shunt between GPIO0 and GND;
remove the shunt between RSTn and GND;
mount the components together and power the device.

No longer necessary to remove the resistors

1 Like

Sweet! I’ve ordered one of this meters and hope to flash it via OTA. But if it doesn’t work it’s nice to have an easier alternative for soldering SMD components. I’ll give some feedback when it arrives. Thanks for your commitment! Cheers.

Hello, I have a small problem, when i restart home assistant does not save me the state of the switch, I mean, the switch is on, I restart home assistant and it appears as off although in reality if it is physically on, I have been playing with the retain in the tasmota console and in the yaml, but I don’t solve it.
let’s see if you can keep an eye on it, greetings and thanks for your work again

Hi @pollinolas,

The approach I have been following (this is a caveat for most MQTT connected Tasmota switches, in Home Assistant), is to add an automation in HA, for publishing a command to force the device to report its status. This automation is triggered after HA is done booting up. For example:

- id: on_hassio_startup
  alias: 'On Home Assistant Startup'
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: 'cmnd/living-room-heater/mem2'
        payload: "20"
    - service: mqtt.publish
      data:
        topic: 'cmnd/living-room-heater/mem3'
        payload: "22"
    - service: mqtt.publish
      data:
        topic: 'cmnd/kitchen-lights/Power1'
    - service: mqtt.publish
      data:
        topic: 'cmnd/kitchen-lights/Power2'
    - service: mqtt.publish
      data:
        topic: 'cmnd/dual-switch/Power1'
    - service: mqtt.publish
      data:
        topic: 'cmnd/dual-switch/Power2'

Alternatively you could add a rule in your device to periodically report the status of its switch(es), but this adds a bit more network usage.

Cheers

Thank you, I had already thought about the status update when starting home assistant,
Could you provide the rule to try?

In HA, you can try something similar to the rule above (replace topic with the correct one in your scenario - on the ZMAi-90 it must be something like ‘cmnd/[your switch name here]/Power’, and configure just one action.

I am very lost to be able to create the rule in the tasmota console.thanks

could be something like this or im wrong:

rule on Switch1#state=ON do publish cmnd/piscina/POWER 1 endon
rule on System#Boot do publish cmnd/piscina/POWER  endon

this is my switch.yaml

  - platform: mqtt
    name: "Motor Piscina"
    state_topic: 'stat/piscina/RESULT'
    value_template: '{{ value_json["POWER"] }}'
    command_topic: 'cmnd/piscina/POWER'
    availability_topic: 'tele/piscina/LWT'
    qos: 1
    payload_on: 'ON'
    payload_off: 'OFF'
    payload_available: 'Online'
    payload_not_available: 'Offline'
    retain: true

Hi @pollinolas,

Looking in hindsight to the problem at hand: a Tasmota switch by default only reports its current state, when it changes (e.g. when you manually press a button, or send a command (e.g. to the cmnd/piscina/POWER topic).

This is not a problem by itself, but it is for HA, because it doesn’t remember the last state the switch was in, after a restart (rightfully so, because the switch may have changed state during the restart on HA).

From a systems optimization point of view, I believe it is best to mitigate this on HA side, by adding the automation that is triggered on HA bootup. This automation instructs the switch to report its state. This is only done once, and ensures that HA becomes in sync with the switch after it reboots.

Adding a rule on Tasmota to periodically report its status, even though functionally it works, I think it is not the best approach, as it adds unnecessary network traffic and load to the MQTT broker. For one device it is not a problem, but on a large network of IoT devices it could cause degradation.

So in sum, my suggestion for your case, would be to add the following code to your automations.yaml:

automation:
  - id: on_hassio_startup
    alias: 'On Home Assistant Startup'
    trigger:
	  platform: homeassistant
	  event: start
    action:
	  - service: mqtt.publish
	    data:
		  topic: 'cmnd/piscina/POWER'

What this does is, when Hass.io boots up, it sends an empty message to the ‘cmnd/piscina/POWER’ topic, causing the device to publish the response in the ‘stat/piscina/RESULT’ topic (every message sent to cmnd/piscina/xxx is interpreted as command xxx in Tasmota). Your HA switch entity is configured to listen to the topic that contains the result (state_topic: ‘stat/piscina/RESULT’), parsing the message that is received and updating the state of the entity accordingly.

On the Tasmota device you don’t need to change anything.

Cheers

2 Likes

thanks a lot bro :+1:

Hello folks, added some more info for the configuration of the ZMAi-90 DIN rail meter/switch:

It is particularly relevant the GPIO13, which can be configured in Tasmota for using the push button in the device for manually toggling the power (something that was no possible in the original Tuya firmware!)

2 Likes

First off, thank you so much, I flashed this with tuya convert and was up and running in minutes, with power monitoring and everything.
Has anyone noticed that sometimes when turning off the relay, it registers it’s state as off, web page says it’s off, mqtt etc, but doesn’t actually turn off the relay?
It’s got a real loud crack as it opens and closes, sometimes it keeps the relay open without making that huge crack sound, and the circuit is still live.

1 Like

Hello @ilan, you may want to take a look at the device console, to see if it is actually receiving /handling the mqtt messages? By default hass.io is optimistic and updates the state of the switch, assuming the switch actually did changed state, when in fact it may have not…