I figured something out using the home-assistant-variables to keep track of runtime for each humidifier.
I created 2 variables.
var.humidifier_up_on_at = epoc timestamp
var.humidifier_up_runtime = runtime in seconds.
I have 2 automations that trigger when the humidifier is turned on and off.
- alias: Humidifier Up Turned On
mode: single
trigger:
- platform: state
entity_id: switch.eb71aa9a76450cd925ijoh
to: 'on'
action:
- service: var.set
data:
entity_id: var.humidifier_up_on_at
value: '{{ now().strftime("%s") | int }}'
- alias: Humidifier Up Turned Off
mode: single
trigger:
- platform: state
entity_id: switch.eb71aa9a76450cd925ijoh
to: 'off'
action:
- service: var.set
data:
entity_id: var.humidifier_up_runtime
value: >-
{{ ((now().strftime("%s") | int) - (states('var.humidifier_up_on_at') | int)) + (states('var.humidifier_up_runtime') | int) }}
When the humidifier is turned on it sets var.humidifier_up_on_at to the current epoc time. When the humidifier is turned off it takes the current epoc and subtracts var.humidifier_up_on_at from that then adds var.humidifier_up_runtime.
That was the tricky part. Now when var.humidifier_up_runtime goes over a set value of something like 21,600 (6 hours in seconds) it will send the notification. I didn’t include that code as I haven’t added it yet.