Hass.io: Mqtt x reboot

Hello,

I am using home assistant (HA) to monitor a water tank with 2 water level sensors (reed switch) hardware used:

  • d1 mini
  • reed switch - water level sensor
    I use the tasmota firmware on the d1 mini.

It works without problems, but if for some reason the home assistant restarts, I lose the status that was sent to mqtt to HA.

How do I get this status again from the level sensors?

You can enable the sensor retain option:
http://<ip_of_your_d1_mini>/cm?cmnd=SensorRetain%201

You should configure the availability_topic, payload_available, payload_not_available parameters in your sensor then:

- platform: mqtt
  name: "Water Tank Sensor"
  state_topic: ".../tele/SENSOR"
  availability_topic: ".../tele/LWT"
  value_template: "..."
  payload_available: "Online"
  payload_not_available: "Offline"

I have the following question:

As sensor is a reed switch (firmware tasmota) was directed to use the state_topic: "stat / tank3000 / POWER2 to monitor the sensor.

If you use tele / … I can not see the result just after 5 minutes

This is because it was necessary according to the tasmota manual to create a virtual relay and switch to monitor the value reed switch in this case would be power2

I’m assuming this implies you have to query power2 to get your information…

You could use PowerRetain then or you use the following automation (I’d prefer the automation).

- alias: "Water Tank state on hassio start-up"
  id: "wtsohsu"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "cmnd/tank3000/power2"
        payload: ""

I have two tanks with 2 sensors.

How to use the automatism to update the status of the 4 sensors?

alias: "Water Tank state on hassio start-up"
id: "wtsohsu"
trigger:
  - platform: homeassistant
    event: start
action:
  - service: mqtt.publish
    data:
      topic: "cmnd/tank3000/power1"
      payload: ""
      topic: "cmnd/tank3000/power2"
      payload: ""
      topic: "cmnd/tank1000/power2"
      payload: ""
      topic: "cmnd/tank1000/power3"
      payload: ""

It’s not working right?
What can I do better in this code?

I’m on mobile, making it hard to prepare the code.

You have to repeat the service and data line for each entry (before each topic).

alias: "Water Tank state on hassio start-up"
id: "wtsohsu"
trigger:
  - platform: homeassistant
    event: start
action:
  - service: mqtt.publish
    data:
      topic: "cmnd/tank3000/power1"
      payload: ""
  - service: mqtt.publish
    data:
      topic: "cmnd/tank3000/power2"
      payload: ""
  - service: mqtt.publish
    data:
      topic: "cmnd/tank1000/power2"
      payload: ""
  - service: mqtt.publish
    data:
      topic: "cmnd/tank1000/power3"
      payload: ""

Please check indentation if it does not work…

Thanks, I’ll do it!