I am new to Home Assistant, and YAML etc, but slowing getting there and using it to do some sensible things. But I am hoping someone can help me solve a problem.
I am trying to automate the pool pump to try and get it to primarily run from spare Solar. But when there is not enough, I am happy for it to keep running.
I have an automation, which switches the pump off once I start needing to import power from the grid which is all working. However, I would like to add a condition which says to leave it on, if the pump has not run at least 4 hours today AND 8 hours in the last 2 days. So I have setup a history_stats sensor which tracks how many hours the pump has run today, as well as in the last to days. And I added a condition that makes sure that these sensors have run for 4 and 8 hours respectively. HOWEVER, this does not work, because the history_stats sensor does not seem to like a number (I assume because it is a time). The error is :-
Error: In 'and' (item 1 of 2): In 'numeric_state': In 'numeric_state' condition: entity sensor.pool_pump_on_today state '' cannot be processed as a number
To give you an idea, my not working code is below :-
- id: '1663655246419'
alias: Pool - Turn off if grid import and it has run 8 hours in 2 days AND 4 hours
today
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.modbus_grid_power_sum
above: 0
for:
hours: 0
minutes: 0
seconds: 0
condition:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.pool_pump_on_today
value_template: ''
above: 4
- condition: numeric_state
entity_id: sensor.pool_pump_on_last_2_days
above: 8
enabled: true
action:
- type: turn_off
device_id: 6bbc4ecb610c42d40ac51b9217de14bb
entity_id: switch.wifi_plug_3_socket_1
domain: switch
mode: single
Clearly a “numeric state” condition does not like what is in history_stats because it is a time.
Can anyone help me with an alternate way to implement this which would achieve what I want to achieve?
I should mention, I have another automation which picks up the pieces, and will turn it off if grid imports is above zero for 30 minutes. But I very much want to have it turn off earlier if we have achieved the runtime target.
Thanks in advance.