I have an entity which contains the electricity prices for the next day in an attribute “data”. When the prices aren’t available yet, the “data” attribute is null according to the template tester. When the prices are available, the “data” attribute contains a list with the time ranges and prices.
I want an automation to send a Matrix message as soon as the prices for the next day are in. The Matrix part works just fine, however, I can’t get the automation to trigger. Isn’t it possible to trigger on an attribute change?
Code:
alias: Nordpool price notice
description: ""
triggers:
- trigger: state
entity_id: sensor.nordpool_prices_tomorrow
attribute: data
not_to:
- null
- unknown
- unavailable
conditions: []
actions:
- action: notify.matrix
metadata: {}
data:
message: >-
{% set minprice = state_attr('sensor.nordpool_prices_tomorrow','data') |
map(attribute='price_per_kwh') | list | min %}
{% set maxprice = state_attr('sensor.nordpool_prices_tomorrow','data') |
map(attribute='price_per_kwh') | list | max %}
Electricity prices tomorrow:
Min. {{ state_attr('sensor.nordpool_prices_tomorrow','data') |
map(attribute='price_per_kwh') | list | min | round(4) }} EUR/kWh from
{{ as_timestamp((state_attr('sensor.nordpool_prices_tomorrow',
'data')|selectattr('price_per_kwh','eq',minprice)|first)['start_time'])
| timestamp_custom('%H:%M')}} to {{
as_timestamp((state_attr('sensor.nordpool_prices_tomorrow',
'data')|selectattr('price_per_kwh','eq',minprice)|first)['end_time']) |
timestamp_custom('%H:%M')}}
Max. {{ state_attr('sensor.nordpool_prices_tomorrow','data') |
map(attribute='price_per_kwh') | list | max | round(4) }} EUR/kWh from
{{ as_timestamp((state_attr('sensor.nordpool_prices_tomorrow',
'data')|selectattr('price_per_kwh','eq',maxprice)|first)['start_time'])
| timestamp_custom('%H:%M')}} to {{
as_timestamp((state_attr('sensor.nordpool_prices_tomorrow',
'data')|selectattr('price_per_kwh','eq',maxprice)|first)['end_time']) |
timestamp_custom('%H:%M')}}
mode: single