Hi there! I’m rather new to HomeAssistant, and I find it quite hard to get into it, the learning curve seems rather steep.
I’ve written some simple code to turn on my Shelly1 (which turns on the water heater; note: I have the shelly app turn off Shelly after 55 minutes) at the 2 cheapest hours:
- sensors:
cheap_hour:
friendly_name: "Cheap hour?"
unique_id: chp_hrs_state
value_template: >-
{% set today=states.sensor.nordpool.attributes.raw_today|sort(attribute='value')%}
{% set current_price = states('sensor.nordpool')|float %}
{% if ( current_price <= today[1].value or current_price <= 0 ) %}
yes
{% else %}
no
{% endif %}
And added this in Automations:
alias: TurnOnShelly
description: ""
trigger:
- platform: state
entity_id:
- sensor.cheap_hour
to: "yes"
condition: []
action:
- type: turn_on
device_id: 726474dd131501f8fd1aea80cb1ed2bd
entity_id: 5de6ab698722f9611f11417540a662f9
domain: switch
mode: single
This works well for the most part, except when the the 2 cheapest hours are X and X+1, because then the state doesn’t change, but simply stays yes, and the automation only turns Shelly on when the state changes to yes.
So a simple solution would be to change its state to ‘no’ every hour. I tried the following, but to no avail:
alias: SetState
description: ""
trigger:
- platform: time_pattern
minutes: "55"
condition: []
action:
- platform: state
entity_id: sensor.cheap_hour
state: no2
mode: single
But this doesn’t seem to work (the editor gives an error: ““Message malformed: Unable to determine action @ data[‘action’][0]””). I feel like I don’t quite know what I’m doing, and ever topic that’s slightly relevant hasn’t offered a solution. Any help would be very appreciated!