Last active
September 4, 2022 17:51
-
-
Save elden1337/d8544fc92e6518835ba689c615a807e0 to your computer and use it in GitHub Desktop.
Price color light (philips hue and nordpool)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- id: '1234567890' | |
alias: Light - Price color | |
trigger: | |
- platform: time_pattern | |
hours: /1 | |
seconds: '5' | |
condition: [] | |
action: | |
- service: light.turn_on | |
data: | |
transition: 10 | |
color_name: '{{states.sensor.price_color.state}}' | |
target: | |
entity_id: light.go | |
mode: single | |
- id: '9876543210' | |
alias: Light - price color next | |
description: '' | |
trigger: | |
- platform: time_pattern | |
minutes: /1 | |
condition: | |
- condition: template | |
value_template: '{{now().minute > 44}}' | |
- condition: template | |
value_template: '{{states.sensor.price_color.state != states.sensor.price_color_next.state}}' | |
action: | |
- repeat: | |
count: 2 | |
sequence: | |
- service: light.turn_on | |
data: | |
transition: 1 | |
brightness: 255 | |
color_name: '{{states.sensor.price_color_next.state}}' | |
target: | |
entity_id: light.go | |
- service: light.turn_on | |
data: | |
transition: 3 | |
brightness: 235 | |
color_name: '{{states.sensor.price_color.state}}' | |
target: | |
entity_id: light.go | |
mode: single |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- platform: template | |
sensors: | |
price_color_value_avg: | |
value_template: > | |
{%set today = states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.today %} | |
{%set tomorrow = states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.tomorrow %} | |
{%set result = namespace(result=[]) %} | |
{%if tomorrow|length == 24%} | |
{% set idx = namespace(value=0) %} | |
{% for i in today %} | |
{% set result.result = result.result + [i] %} | |
{%set idx.value = idx.value+1%} | |
{% endfor %} | |
{% for i in tomorrow %} | |
{% set result.result = result.result + [i] %} | |
{%set idx.value = idx.value+1%} | |
{% endfor %} | |
{%else%} | |
{%set result.result = today%} | |
{%endif%} | |
{{result.result|average}} | |
price_color_next: | |
value_template: > | |
{%set nextval = 0%} | |
{%if now().hour == 23%} | |
{%set nextval = states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.tomorrow[0]%} | |
{%else%} | |
{%set nextval = states.sensor.nordpool_kwh_se3_sek_3_10_025.attributes.today[now().hour +1]%} | |
{%endif%} | |
{%set nextval = (((nextval|float/states.sensor.price_color_value_avg.state|float)-1))|round(2)%} | |
{%set nextcolor = ""%} | |
{%if nextval > 0.7%} | |
{%set nextcolor = "red"%} | |
{%elif nextval > 0.3%} | |
{%set nextcolor = "orange"%} | |
{%elif nextval > -0.3%} | |
{%set nextcolor = "yellow"%} | |
{%elif nextval > -0.5%} | |
{%set nextcolor = "lightgreen"%} | |
{%else%} | |
{%set nextcolor = "green"%} | |
{%endif%} | |
{{nextcolor}} | |
price_color: | |
value_template: > | |
{%set color = ""%} | |
{%set currentval = (((states.sensor.nordpool_kwh_se3_sek_3_10_025.state|float/states.sensor.price_color_value_avg.state|float)-1))|round(2)%} | |
{%if currentval > 0.7%} | |
{%set color = "red"%} | |
{%elif currentval > 0.3%} | |
{%set color = "orange"%} | |
{%elif currentval > -0.3%} | |
{%set color = "yellow"%} | |
{%elif currentval > -0.5%} | |
{%set color = "lightgreen"%} | |
{%else%} | |
{%set color = "green"%} | |
{%endif%} | |
{{color}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment