HA Automation for setting the color of a Blue Series LED based on temp

Here’s my take at setting the LED strip of a Blue Series switch based on temp.

I’m running HA with Zigbee2MQTT and pulling temperature info from a sensor I’ve setup that reads my Davis weather station outside.

The gist:

(note all values are imperial, aka F)
If the temp is below 0, then set the color to 220 which is purple. If temp is over 85, then set the color to 0 which is red. For temps between 0 and 85, the color is based off a simple linear equation: COLOR = -2.5882*TEMP + 220.

If you want to use the automation below, just adjust your temp sensor to match your use case and adjust the MQTT topics as necessary.

Hopefully this is useful to those of you looking to implement something similar!

alias: LED Color by Temp
description: >-
  Sets the LED color based on the outside temp. Temps < 0 are set to Purple
  (color 220) and colors > 85 are set to Red (color 0). For temperatures in
  between, colors are set to the a value between 0 and 220 based on the temp
  using a linear equation: C = -2.5882T + 220.
trigger:
  - platform: time_pattern
    minutes: /1
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ states('sensor.current_outside_temp')|int < 0 }} "
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Media Overhead/set
              payload: "{\"ledColorWhenOff\": 220}"
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Media Overhead/set
              payload: "{\"ledColorWhenOn\": 220}"
      - conditions:
          - condition: template
            value_template: "{{ 0 < states('sensor.current_outside_temp')|int <=85 }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Media Overhead/set
              payload_template: >-
                {{ {'ledColorWhenOff': (-2.5882 *
                (states('sensor.current_outside_temp')|float) +
                220)|int}|to_json }}
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Media Overhead/set
              payload_template: >-
                {{ {'ledColorWhenOn': (-2.5882 *
                (states('sensor.current_outside_temp')|float) +
                220)|int}|to_json }}
      - conditions:
          - condition: template
            value_template: "{{ states('sensor.current_outside_temp')|int > 85 }} "
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Media Overhead/set
              payload: "{\"ledColorWhenOff\": 0}"
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Media Overhead/set
              payload: "{\"ledColorWhenOn\": 0}"
mode: single
1 Like