MQTT Publish Relay State cyclical

Hey Guys,

I wan’t to send the state of a relay every hour. The reason is that Telegraf only put the value in InfluxDB2… Grafana Dashboars sucks wen there is no value in the Timerange…

Mike

And where is your issue?
There is an mqtt.publish action/service

1 Like

Hello,

But where can I set the interval for the publish of the relay?

mike

You can use an automation with a time pattern trigger

Hy,

Oh… I forgot… I don’t have HA… i wan’t to do this directly on the ESPHome :slight_smile:

There is a time component allowing to do the same in pure ESPhome fashion

Now, not sure why you’d want that automation based on time rather than plainly on state changes.

You could just use the mqtt component to have the values published to mqtt

The reason: when the relay is OFF for more than 24 Hours, there is no value in the influxDB for the last 24 hours… Then the Grafana Dashboard shows “No Data” instead of “OFF”. I hope my bad english allows me to explain this to you :slight_smile:

I use the MQTT Component and it works perfect for “publish on change”
I already have the Time Component in use… but i dont know what to “trigger” do get the sensor/output to publish a payload

IIRC, grafana allows to use “last value” when there are gaps in the data, doesn’t it?

But the Querry has the Timerange. And when i want to view the Data from the last 24 Hours and der is no Data there is a problem

Not sure what you mean. The trigger is the on_time of the time component, and the action mqtt.publish

Is it necessary to do it this way:


on_time:
      # Every hour
      - seconds: 0
        minutes: 0
        then:
           - mqtt.publish:
               topic: some/topic
               payload: id(some_sensor).state

or is there a easier way to only “say the sensor to publish now”

maybe the “component.update” action?

mike

Fact is you want time to be the trigger, so I don’t see how it could be “easier” according to you…

okay thank you for your help :slight_smile:

:point_down:

  • force_update (Optional, boolean): If true, this option will force the frontend (usually Home Assistant) to create a state changed event when the sensor updates even if the value stayed the same. Some applications like Grafana require this when working with Home Assistant, but beware it can significantly increase the database size. Defaults to false.

Not sure it will work for the OP, as the state of the switch won’t change in ESPhome either