Lovelace - entity-button

Hey all been working on updating my front end, i have a page that i am using for simple push button home control page. I was trying to use entity-button to control my garage door, I am trying to figure out how i could change the icon based on a binary-sensor status. I know i can do this seperate from the button but i would like to see if i could put all the info on the button itself.

I have tired a couple different ways of doing it none seem to be working. Below is my latest iteration of what i have tried.

type: entity-button
tap_action:
  action: toggle
hold_action:
  action: more-info
show_icon: true
show_name: true
entity: switch.garage_door
icon_template: |-
  {% if is_state('binary_sensor.garage_position', 'on') %}
    'mdi:garage'
  {% else %}
    'mdi:garage-open'
  {% endif %}

Any ideas what i am doing wrong?

I am getting the following error btw

Expected a value of type `undefined` for `icon_template` but received `"{% if is_state('sun.sun', 'above_horizon') %}\n mdi:weather-sunny\n{% else %}\n mdi:weather-night\n{% endif %}"`.

Looks to me like icon_template is a feature of sensor: not the lovelace ui entity-button.

remove

In your customize section (in the UI or in Yaml):

in the UI (configuration → customize)

Add the custom field device_class with it set equal to garage_door


or in yaml in the customize section (inside the homeassistant section):

homeassistant:
  customize:
    binary_sensor.garage_position:
      device_class: garage_door

I recommend going the UI route.

Setting that will automatically switch your icon without a template to the exact icons that you want. All of that is discussed in the documentation for binary_sensors.

Is there a way to invert this? the way my unit work the sensor is on when the garage door it closed, not open.

You’d have to create a template sensor then.

binary_sensor:
  - platform: template
    sensors:
      garage_position_inverted:
        value_template: >
          {{ not is_state('binary_sensor.garage_position', 'on') }}
        device_class: garage_door

Perfect i got the sensor working properly. Thank you. I know i could do a frame with the sensor and button. Do you know if it is possible to incorporate the two so that the icon of the button directly reflects the sensor?

It should be doing it. You might need to CTRL+F5 your browser to refresh the cache. If it doesn’t, you could always incorporate the custom:button-card from the home assistant community store (HACS).

I just fond my problem i think, i think it is the programing i have on the switch that is overriding the icon to gate… I will have to take it down and reflash it. bah.

Thanks