We have solar and a battery bank with inverter for our electricity and I’d like to have one of our RGB ceiling lights act as a status indicator for the state of charge for our batteries.
I have created an automation as per following, but it doesn’t seem to work…
I’ve looked at this for some time now but am now stuck with what else I should try.
Current automation set-up so far:
sensor:
- platform: template
sensors:
soc_light_colour:
value_template: >
{% set soc = states('sensor.batterystateofcharge')|float %}
{% set red = ((100 - soc) * 2.55)|int %}
{% set green = (soc * 2.55)|int %}
{{ '[' ~ red ~ ',' ~ green ~ ',0]' }}
automation:
- alias: Light indicator for SOC
trigger:
- platform: state
entity_id: sensor.soc_light_colour
action:
- service: light.turn_on
data_template:
entity_id: light.officelight2
brightness_pct: 75
rgb_color: "{{ states('sensor.soc_light_colour') }}"
Instead of using the python templates with little documentation and examples available I changed tack and used a send mqtt message action instead. That is working now. Just have to fiddle with the colours so I can see them well enough… (my colour perception is a bit impaired )
Anyway, for others, following is the automation that is working for me currently:
sensor:
- platform: template
sensors:
soc_light_colour:
value_template: >
{% set soc = states('sensor.batterystateofcharge')|float %}
{% set red = ((100 - ((soc - 50) * 2)) * 2.55)|int %}
{% set green = ((soc - 50) * 2 * 2.55)|int %}
{{ red ~ ',' ~ green ~ ',0' }}
automation:
- alias: Light indicator for SOC
trigger:
- platform: state
entity_id: sensor.soc_light_colour
action:
- service: mqtt.publish
data:
topic: cmnd/officelight2/Color2
payload_template: "{{ states('sensor.soc_light_colour') }}"
- service: mqtt.publish
data:
topic: cmnd/officelight2/Dimmer
payload: 100