jeffl
April 1, 2018, 12:16am
1
I have a sensor that tells me light level and temperature outside.
I have RGB lights indoors that I want to set based on the two sensors above.
If temp > 80, turn the light red
If temp < 80 & temp > 70, turn the light green
if temp < 70, turn the light blue.
I have created a binary_sensor for the light/dark threshold.
Here’s a sample automation.
trigger:
- platform: numeric_state
entity_id: sensor.temperature
above: 80
condition:
- condition: state
entity_id: binary_sensor.isdark
state: 'on'
action:
- service: mqtt.publish
data_template:
topic: "<light setting topic>"
payload: '{"state":"ON","color":{"r":255,"g":100,"b":100},"brightness":6,"effect":"solid"}'
I’m using 3 automations to accomplish this which works kinda, but is not ideal (eg: missing setters for exactly 80 or 70).
I want it to change based on temp, but only want it on when it’s dark outside. Thanks!
jeffl
April 1, 2018, 5:38am
2
Here’s what I came up with.
Created a template sensor to track the temperature ranges…
configuration.yaml
sensor:
- platform: template
sensors:
rgbtemp:
friendly_name: RGB Temp
value_template: >-
{% if states('sensor.temperature')|float > 79.9 %}
Hot
{% elif states('sensor.temperature')|float < 70 %}
Cold
{% else %}
Just Right
{% endif %}
Then use that in the automation…
automation.yaml
- alias: Stair Pathway Lighting
trigger:
- platform: state
entity_id: binary_sensor.isdark
to: 'on'
- platform: state
entity_id: sensor.rgbtemp
condition:
- condition: state
entity_id: binary_sensor.isdark
state: 'on'
action:
- service: mqtt.publish
data_template:
topic: "<light setting topic>"
payload: >-
{% if is_state('sensor.rgbtemp', 'Hot') %}
{"state":"ON","color":{"r":255,"g":100,"b":100},"brightness":6,"effect":"solid"}
{% elif is_state('sensor.rgbtemp', 'Cold') %}
{"state":"ON","color":{"r":100,"g":100,"b":255},"brightness":6,"effect":"solid"}
{% else %}
{"state":"ON","color":{"r":100,"g":200,"b":100},"brightness":6,"effect":"solid"}
{% endif %}
I didn’t want to spam MQTT for every temperature change so I used 2 triggers to only send if it gets dark or the temp causes rgbtemp to change.