Binary sensor won't show the right state

Hi!
I’m trying out the binary sensor and started with this:

binary_sensor:
  - platform: template
    sensors:
      hm_lan:
        value_template: '{% if is_state("device_tracker.keq1024131fritzbox", "home") %}online{% else %}offline{% endif %}'
        friendly_name: 'HM LAN'
        sensor_class: connectivity

The template should work since it works with the Templates-Tool. In there it shows the state ‘online’.
In the States section the sensor appears but with the wrong state: ‘offline’.

Where’s the catch?
Any help is appreciated!!!

Hi!

I think binary_sensors only accept True or False as input.
Try this as your value template:

value_template: '{{ states.device_tracker.keq1024131fritzbox.state == "home" }}'

Let me know if this works

edit: home in double quotes

I just found this thread:

@PtP did the answer:

This works for me now:

  sensor:
      - platform: template
        sensors:
          status_hm_lan:
            value_template: '{% if is_state("device_tracker.keq1024131fritzbox", "home") %}online{% else %}offline{% endif %}'
            friendly_name: 'HM LAN'
            icon_template: '{% if is_state("device_tracker.keq1024131fritzbox", "home") %}mdi:server-network{% else %}mdi:server-network-off{% endif %}'

Thanks!!

1 Like