Set button as on/active as default?

I have a button that calls a script. Can I set the icon as on state (yellow) as default? It might be very simple or obvious but somehow I can’t find a way to do it.

              - type: button
                name: Canvas
                icon: mdi:vector-square    
                show_state: true
                initial_state: on               
                tap_action:
                  action: call-service
                  service: script.turn_on
                  service_data:
                    entity_id: script.canvas  

I have tested with show_state or initial_state but it makes no different. Can it be done?

Thanks.

You can create a fake entity that’s always on. Binary template sensor is the easiest.

template:
- binary_sensor:
  - name: Always On
    state: on

then just use binary_sensor.always_on on every button that runs a script and needs to be always on.

Thanks for the idea.
I have an entity that is always on so I use its state instead.
The button now works as I want.

1 Like