TelePeriod and MQTT messages

I’m using a Kogan energy monitor switch running Tasmota 9.3.1 and have added it to Lovelace using the latest Tasmota HA integration. All works as expected.

However I notice this delay between switching the power and the dashboard refreshing the rest of the values such as current, power, voltage etc. This comes as a result of TelePeriod (60 in my case). So Tasmota sends the data every TelePeriod to the broker where the dashboard picks it up. Again works as designed.

Now if I wanted to make these updates more realtime the obvious answer would be to decrease TelePeriod. However this unnecessarily increases network traffic.

Is there a way to fire the MQTT sensor data update when the switch is activated (note: This is not very important for the Kogan switch but there would be other examples where a more realtime update could be relevant)?

You can do this with an automation. The automation can be triggered with change of switch state. The action type should be choose. And in it the first option should be if the switch is on and second should be if the switch is off.

The action when switch is on should be to call the service mqtt.publish with the topic “cmnd/mqtt_topic/teleperiod” and the payload should be 10.

The action when switch is off should be to call the service mqtt.publish with the topic “cmnd/mqtt_topic/teleperiod” and the payload should be 60.

If you need more help please ask.

Looking at the console Tasmota sends the following MQTT message (example) at the TelePeriod intervals which then gets picked up by Home Assistant

09:57:21.399 MQT: tele/tasmota-xxxxxx/SENSOR = {"Time":"2021-03-26T09:57:21","ENERGY":{"TotalStartTime":"2020-08-13T15:17:43","Total":75.316,"Yesterday":0.155,...

So rather than changing the TelePeriod and correspondingly triggering Tasmota to send the Sensor data at a higher TelePeriod frequency wouldn’t it be possible to directly publish the sensor data?

I use this automation/script when HA starts to get the status without waiting for the Tele period.

  startupalltasmota:
    alias: Tasmota Restore State at Startup
    sequence:
    - data:
        payload: ''
        topic: sonoffs/cmnd/state
      service: mqtt.publish
    - data:
        payload: ''
        topic: nodemcu/cmnd/state
      service: mqtt.publish

Sonoffs is the group for most of my switches and I also have a nodemcu group hence the 2 publish commands. So make an automation to send the blank payload to the state and it should work for you.

1 Like

Was able to fire the topic including /state but it appears the lovelace dashboard picks up the topic ending .../SENSOR as per my example above; i.e. voltage, current, power etc.

So not really knowing how this works I published an empty payload to topic .../SENSOR but it threw an MQTT error.

Two questions:

  • How does Home Assistant internally map an MQTT message to an entity_ID?

  • How can I trigger the topic ending .../SENSOR on the Tasmota device?