Custom Card - Changing icon color based on state - error: expected float for dictionary value @ data['temperature']

When I run this script with the button, I am getting this error:
Stopped because an error was encountered at July 13, 2023 at 12:58:17 PM (runtime: 0.01 seconds)

expected float for dictionary value @ data[‘temperature’]

A user here helped me setup my button.
I am creating a button that turns on my AC in the garage, but it also sets the hvac mode to cool and sets the temperature to 72.
I will be doing the exact same thing for the heat portion.

Here is my button, it is working perfectly, except I can’t get it to set an off color and on color. The default colors are too similar. i want it to be that light blue when off, and white when on.

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: script.1689247316109
  data:
    mode: cool
    temp: 72
name: Cool
icon: mdi:snowflake
entity: climate.40681930235404_climate
show_state: true

The button turns it on and off as it should, and sets the mode and temp.
But no matter what I do, I can’t add logic to change color based on state, I keep getting an error that it is not supported or unexpected.

So I tried a custom card.
The custom card will fail when I run the script.
Whats funny is the icon DOES change color, when i activate the other button lol.
But I can’t run the script on the custom card button.

type: custom:button-card
show_name: true
show_icon: true
tap_action:
  action: call-service
  service: script.1689260694043
  data:
    mode: cool
    temp: 72
name: Cool
icon: mdi:snowflake
entity: climate.40681930235404_climate
state:
  - value: 'off'
    color: rgb(52, 125, 235)
  - value: 'on'
    color: rgb(255,255,255)

When trying to use that card, here is the error from the trace:

Stopped because an error was encountered at July 13, 2023 at 12:58:17 PM (runtime: 0.01 seconds)

expected float for dictionary value @ data[‘temperature’]

(I created a duplicate of the original script for the custom button card, cause I keep getting that float error, so I would not mess up the one that is actually working.

alias: GarageAC_OnOff (Duplicate)
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ mode != states('climate.40681930235404_climate') }}"
        sequence:
          - service: climate.set_temperature
            data_template:
              temperature: "{{ temp }}"
              hvac_mode: "{{ mode }}"
            target:
              entity_id: climate.40681930235404_climate
    default:
      - service: climate.turn_off
        data: {}
        target:
          entity_id: climate.40681930235404_climate
fields:
  mode:
    name: Mode
    example: cool
  temp:
    name: Temperature
    example: 72
mode: single

i tried doing a pipe to float, no dice, most likely cause I am doing it wrong :slight_smile:

So I am seeing that the normal button (the one working but not changing color) is passing back temp and hvac mode:

Executed: July 13, 2023 at 1:02:35 PM
Result:
params:
  domain: climate
  service: set_temperature
  service_data:
    temperature: 72
    hvac_mode: cool
    entity_id:
      - climate.40681930235404_climate
  target:
    entity_id:
      - climate.40681930235404_climate
running_script: false

My custom button that is changing color, but wont execut the script (changes color due to the other button being used), is NOT passing back hvac mode or temp:

Executed: July 13, 2023 at 2:05:03 PM
Result:
params:
  domain: climate
  service: set_temperature
  service_data:
    temperature: ''
    hvac_mode: ''
    entity_id:
      - climate.40681930235404_climate
  target:
    entity_id:
      - climate.40681930235404_climate
running_script: false

Custom button card uses some legacy style configuration keys. For example, it uses the key service_data, not data in it’s Call Service action.

Also, I don’t think ‘on’ is a valid state for your climate entity, it is usually one of the following: cool, heat, off, heat_cool

type: custom:button-card
show_name: true
show_icon: true
tap_action:
  action: call-service
  service: script.1689260694043
  service_data:
    mode: cool
    temp: 72
name: Cool
icon: mdi:snowflake
entity: climate.40681930235404_climate
state:
  - value: 'off'
    color: rgb(52, 125, 235)
  - value: 'cool'
    color: rgb(255,255,255)
1 Like

Dude, THANK YOU for all the help today, on this one and the other one.
That is exactly what I was just looking into to see if the custom card takes data:
I was looking through its docs and did not see it and then saw you responded.
Swapped that out for service_data…WORKS!
THANKS!

Custom button card has so many options, it’s easy to miss stuff in those docs.

1 Like