I find the programming language in Home Assistant incredibly hard to understand. This project should have taken hours instead of days, but here it is. The price indicator that shows the family when to activate the dish washer. The leftmost lamp is the price right now, the second and third is the price next hour and the following. The final lamp is a mean price indicator for hour 3-6.
Don’t know if linking to own pages is allowed, but you can see the full build project (in Swedish) on my blog: Bygg din egen elprislampa – Tomas Heed
- id: "price_indicator"
alias: Ljusstake
mode: single
variables:
today_prices: "{{ state_attr('sensor.nordpool', 'today') }}"
tomorrow_prices: "{{ state_attr('sensor.nordpool', 'tomorrow') }}"
prices: "{{ today_prices + tomorrow_prices}}"
hour: " {{now().hour | int}}"
price0: "{{prices[hour]}}"
price1: "{{prices[hour + 1]}}"
price2: "{{prices[hour + 2]}}"
price3: "{{(prices[hour + 3] + prices[hour + 4] + prices[hour + 5]) /3}}"
index0: "{{((price0 - 0.44) * 10) | int }} "
index1: "{{((price1 - 0.44) * 10) | int }} "
index2: "{{((price2 - 0.44) * 10) | int }} "
index3: "{{((price3 - 0.44) * 10) | int }} "
index0m: "{% if (index0 < 0) %} {{ 0 }} {% elif (index0 > 9) %} {{ 9 }} {% else %} {{ index0 }} {% endif %}"
index1m: "{% if (index1 < 0) %} {{ 0 }} {% elif (index1 > 9) %} {{ 9 }} {% else %} {{ index1 }} {% endif %}"
index2m: "{% if (index2 < 0) %} {{ 0 }} {% elif (index2 > 9) %} {{ 9 }} {% else %} {{ index2 }} {% endif %}"
index3m: "{% if (index3 < 0) %} {{ 0 }} {% elif (index3 > 9) %} {{ 9 }} {% else %} {{ index3 }} {% endif %}"
colors:
[
[0, 255, 0],
[63, 255, 0],
[127, 255, 0],
[190, 255, 0],
[255, 255, 0],
[255, 200, 0],
[255, 150, 0],
[255, 100, 0],
[255, 50, 0],
[255, 0, 0],
]
triggers:
- trigger: state
entity_id:
- sensor.nordpool
- trigger: time
at: "23:00:00"
id: turn_off
actions:
- choose:
- conditions:
- condition: trigger
id: turn_off
sequence:
- action: light.turn_off
entity_id:
- light.stake_1
- light.stake_2
- light.stake_3
- light.stake_4
- conditions:
- condition: template
value_template: "{{ hour > 7 and hour < 23 }}"
sequence:
- action: light.turn_on
entity_id: light.stake_1
data:
rgb_color: "{{ colors[index0m] }}"
- action: light.turn_on
entity_id: light.stake_2
data:
rgb_color: "{{ colors[index1m] }}"
- action: light.turn_on
entity_id: light.stake_3
data:
rgb_color: "{{ colors[index2m] }}"
- action: light.turn_on
entity_id: light.stake_4
data:
rgb_color: "{{ colors[index3m] }}"