Change Sate on LoveLace Card

I have a script with a “Send Command” to turn a TV on. The same script will turn it off again.

How would I store the state and how would I implement that in a card in my love lace dashboard so that when I press it the ICON shows an ON TV State and if I press it again it shows an OFF State?

My idea was to use a HELPR TOGGLE but again now sure how to put it into a card or which card type to use.

Any suggestions?

Do you have a binary sensor that indicates whether the TV is on? If so, you should be able to wrap the whole thing in a template switch.

1 Like

@ondras12345 I have created the Template Switch. Seams to work. But how do you display the switch on the dashboard so the icon set by the template switch is diaplayed? i.e. if State is ON the icon for On is displayed and visa versa

Try adding a button card.

extend your binary sensor with this

    icon: >
      {% if is_state('binary_sensor.X', 'off') %}
        mdi:icon-off
      {% else %}
        mdi:icon-on
      {% endif %}

So my TV is based on a Switch template, from a booleen input. (Ithis maybe the wrong approach)

switch:
  - platform: template
    switches:
      tv_kogan:
        value_template: "{{ is_state('input_boolean.kogantvstate', 'on') }}"
        turn_on:
          service: remote.send_command
          data:
            device: Kogan_TV
            command: turnPowerOnOff
          target:
            entity_id: remote.loungeroomremote_remote
        turn_off:
          service: remote.send_command
          data:
            device: Kogan_TV
            command: turnPowerOnOff
          target:
            entity_id: remote.loungeroomremote_remote
        entity_picture_template: >-
          {% if is_state('input_boolean.kogantvstate', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

With dashboard entry looking like this.

show_name: true
show_icon: true
type: button
tap_action:
  action: toggle
entity: switch.tv_kogan
show_state: true

However all I get is the Lightening bolt Icon… Any suggestions?

You probably need icon_template instead of entity_picture_template.