Need help with Custom Button for callbox

Hi,

my first post. I’m a beginner and want to have a custom button card which after pressing the button, switches my wallbox on and according to the status of a binary_sensor (a modus discrete input register) changes its color.

Pressing the button and switching the wallbox works fine. just the change of color according to the binary_sensor does not work.

What do I need to change?

type: custom:button-card
entity: button.zentrale_wallbox_freigabe_taster
icon: mdi:button-pointer
color_type: icon
styles:
  card:
    - height: 100px
tap_action:
  action: toggle
  data:
    entity: binary_sensor.wallbe_in_en
    state:
      - value: true
        color: var(--accent-color)
      - value: false
        color: var(--primary-color)

Edit: may be it is due to half the second the binary_sensor needs to flip its state?? If so, how to postpone the reading of the binary_sensor?

A binary sensor’s state is “on” or “off” not “true” or “false”.

I tried this as well. Did not work. Also tried with ‘1’/‘0’, 0x01, 0x00 etc… Didn’t work either. :frowning:

Sorry, I missed the bigger issue… There is no such action as toggle for binary sensors. The general convention in HA is that sensor’s are not directly controlled by user input, for that we use input entities/Helpers like Input Booleans.

If the source integration has actions that allow the user to alter/update the sensor’s value, you need to use call-service with those actions, not toggle.

In any case, the state values for color will need to be based off of "on” and “off”.

Thank you. Toggling works well, because that is a button (button.zentrale_wllbox_freigabe_taster) defined in my RaspberryMatic. I don’t switch/write the binary_sensor directly.
I press the defined card and the wallbox switches fast and properly.

Problem SOLVED.

This was the button I ended up with:

type: custom:button-card
tap_action:
  action: perform-action
  perform_action: script.wallbox_freigeben_sperren
entity: binary_sensor.wallbe_in_en
color_type: card
name: |
  [[[
    if (entity.state == 'on')
      return 'Laden AUSSCHALTEN';
    else
      return 'Laden EINSCHALTEN';
  ]]]
styles:
  card:
    - height: 100px
size: 50%
show_state: false
state:
  - value_template: |
      {% if states('binary_sensor.wallbe_in_en') == 'on' %}
        true
        icon: mdi:ev-station
      {% else %}
        false
        - icon: mdi:car-electric-outline
      {% endif %}
icon: |
  [[[
    if (entity.state == 'on') return 'mdi:ev-station';
    else return 'mdi:car-electric-outline';
  ]]]

… and this is the script … because my callbox needs an impulse not permanent high signal an input register.

sequence:
  - action: switch.turn_on
    target:
      entity_id: switch.keller_flur_wallbox
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 500
  - action: switch.turn_off
    target:
      entity_id: switch.keller_flur_wallbox
    data: {}
alias: wallbox_freigeben_sperren
description: ""