Getting switch state in Entity Button Card

I’m using an Entity Button card to set my pool/spa switches. Is there any way to show the current state as well?

The reason is, my pool runs on its own automation system (turning on the pool at noon). If I don’t use HA to turn on the pool, then the switch state in lovelace shows as off. The two switches below are command line switches that call a curl/RESTful command.

  - type: horizontal-stack
    cards:          
      - type: entity-button
        entity: switch.pool_switch
        name: Pool
        icon: mdi:swim
        tap_action: toggle
      - type: entity-button
        entity: switch.spa_switch
        name: Spa
        icon: mdi:fire
        tap_action: toggle

In the image below, the pool pump is on, but since I didn’t turn it on with HA, it shows as off.

1 Like

It’s likely the fact that you’re using a command-line script to turn the light on. HA probably doesn’t recognize that, since it’s not an “integrated component”. Programatically setting the state of an entity is tricky (at least to me).

For example, my Hue lights show accurately in HA whether I turn them on with HA or with Alexa, because the Hue bridge that controls/senses the light’s state is wired in to HA. Does that make sense?

There might be a way to do what you want using Node-RED, from which I think you can manually manipulate the state of the switch(button), along with performing the action you want.

I’m not an expert, so someone may likely contradict me. I’m just throwing it out there.

Yup that makes perfect sense. I tried to play around with using actual RESTful switches but was unsuccessful. I’ve got the state of the pool in a sensor… wish there was some way to update the icon based on that sensor.

I’m almost positive there’s some kind of direct command you can send to change the state of an entity. Like I said, I’m not an expert, but I think it’s out there. The problem is that I think it’s a “coding” thing rather than an “interface” thing.

You may be able to rig something up using a binary sensor that you can set to on/off or 1/0… but I don’t have a lot of experience with 'em. Then there’s likely a way you can tie the sensor state to the state of your button.

You might also want to look into the custom button called button-card. It’s got more options than entity-button and might do what you need.

Good luck.

Thanks for the reply. I think I solved it.

Just using the result of the pool sensor state did not solve it. I had to include the command_state. When that is included, the command_state evaluation is ignored and the value_template is used to determine the state. Another case of me RFTM :slight_smile:

  pool_switch:
     command_on: "/usr/bin/curl -X GET 192.168.2.122:3000/circuit/6/set/1"
     command_off: "/usr/bin/curl -X GET 192.168.2.122:3000/circuit/6/set/0"
     command_state: "/usr/bin/curl -X GET 192.168.2.122:3000/circuit/6/"
     value_template: '{{ states.sensor.pool_state.attributes.status == 1 }}'
     friendly_name: "Pool Switch"