ESPHome safe off MQTT

Hello,

I’m trying to create a safe off function in esphome if home assistant is not running.

I’ve read and the documentation, but i cant get the point what i’m doing wrong.

the error is:
condition:
for:
time: 3min
condition:

        Unable to find condition with the name 'id'.
        id: hassonline
        state: offilne

the code is:

text_sensor:

  - platform: mqtt_subscribe
    name: "HASS Online"
    id: hassonline
    topic: homeassistant/status
    on_value:
      if:
        condition:
          for:
            time: 3min
            condition: 
              id: hassonline
              state: "offilne"
        then: 
          - switch.turn_off: relay1
          - switch.turn_off: relay2
          - switch.turn_off: relay3
          - switch.turn_off: relay4

That’s the condition syntax for a global variable, not a sensor.

Try:

    on_value:
      if:
        condition:
          for:
            time: 3min
            condition: 
              lambda: |-
                return id(hassonline).state == "online";

or - because you are executing the action in the sensor:

    on_value:
      if:
        condition:
          for:
            time: 3min
            condition: 
              lambda: |-
                return x == "online";
1 Like