I am attempt to have it so that when my home battery is rapidly charging off the grid, the switch changes from red (0-15% SoC) up to blue, at 100% SoC, while pulsing (when the Alarm is off, as the light switches indicate alarm status when it’s on).
alias: Tesla Rapid Grid Charging Indicator Lights
description: Indicator lights for Tesla charging from the grid
trigger:
- platform: numeric_state
entity_id: sensor.grid_power
above: 14500
condition:
- condition: state
entity_id: binary_sensor.battery_charging
state: "on"
- condition: state
entity_id: alarm_control_panel.alarmo
state: disarmed
action:
- variables:
battery_level: "{{ states('sensor.battery') | int }}"
color: >
{% if battery_level <= 15 %}
1
{% elif battery_level <= 100 %}
{{ (1 + (battery_level - 15) * 2) | int }}
{% else %}
170
{% endif %}
- type: issue_all_led_effect
domain: zha
device_id: 0653d29eb9407d682856d13d0208937c
effect_type: Pulse
color: "{{ color }}"
level: 100
duration: 255
mode: single
I’ve also tried making the color: "{{ color | int }}
Either way I get the error:
Message malformed: expected int for dictionary value @ data[‘color’]
Ah ha. Try changing the battery_level=states('sensor.battery') | int to battery_level: states('sensor.battery') | int
“Message malformed: Integration ‘’ not found”
I don’t think the issue has anything to do with the variables, because I have a working automation that uses them as they are (when the grid is offline, it makes the color of the switches indicate battery level in the same way-- but no pulsing.
As in, this works-- there’s just no way (that I know of) to add pulsing to it:
alias: Light Switches Display Battery Level when Grid Offline
description: >
Changes status light colors based on Tesla home battery level when the grid is
offline.
trigger:
- platform: state
entity_id: binary_sensor.grid_status_2
to: "off"
- platform: state
entity_id: sensor.battery
condition:
- condition: state
entity_id: binary_sensor.grid_status_2
state: "off"
action:
- service: number.set_value
target:
entity_id:
- number.inovelli_vzm31_sn_default_all_led_off_color
- number.light_switch_default_all_led_on_color_2
- number.inovelli_vzm31_sn_default_all_led_off_color_2
- number.inovelli_vzm31_sn_default_all_led_on_color_2
- number.inovelli_vzm31_sn_default_all_led_off_color_4
- number.inovelli_vzm31_sn_default_all_led_on_color_4
- number.light_switch_default_all_led_off_color_2
- number.light_switch_default_all_led_on_color
- number.light_switch_default_all_led_off_color
- number.inovelli_vzm31_sn_default_all_led_on_color
- number.inovelli_vzm31_sn_default_all_led_off_color_3
- number.inovelli_vzm31_sn_default_all_led_on_color_3
- number.light_switch_default_all_led_off_color_4
- number.light_switch_default_all_led_on_color_4
- number.light_switch_default_all_led_off_color_5
- number.light_switch_default_all_led_on_color_5
- number.light_seitch_default_all_led_off_color_5
- number.light_seitch_default_all_led_on_color_5
- number.inovelli_vzm31_sn_default_all_led_off_color_5
- number.inovelli_vzm31_sn_default_all_led_on_color_5
- number.inovelli_vzm31_sn_default_all_led_off_color_6
- number.inovelli_vzm31_sn_default_all_led_on_color_6
- number.light_switch_room_default_all_led_off_color_5
- number.light_switch_room_default_all_led_on_color_5
- number.light_switch_shower_default_all_led_off_color_5
- number.light_switch_shower_default_all_led_on_color_5
data:
value: >
{% set battery_level = states('sensor.battery') |
int %} {% if battery_level <= 15 %}
1
{% elif battery_level <= 100 %}
{{ 1 + (battery_level - 15) * 2 }}
{% else %}
170
{% endif %}
mode: single
Similarly, this also works (what I’m currently using for the purpose of this thread)-- it’s just limited to 7 color steps to indicate charge level, instead of 100. But, this working implies my trigger and conditions are fine-- it’s just the setting of the color/pulsing that is snagging it.