#Message only when power has been above certain level and drops
1 messages · Page 1 of 1 (latest)
you could have another automation to turn that automation on/off as needed 🙂
I assume you get the message because the device became unavailable?
you could make a template binary sensor that functions as a latch and trigger off that instead
something like: {{ states('sensor.shelly_power') | float(0) > 100 or (states('sensor.shelly_power') | float(0) > 10 and this.state | bool) }} - you can also filter out things like unavailable, though if you want to do a for equivalent, you'd need to add a statistics sensor with the max function
You need some way to track whether the printer is on or off. All the previous suggestions essentially do that in different but slightly convoluted ways.
Personally I’d create an entity that explicitly represents the printer’s on/off state. Once you have that, using it as a trigger for notifications is easy.
If you want to consider it ON when power goes above 50W and only consider it OFF when the power drops below 50W for 30 seconds, you have two good options:
- If you want to do everything in the UI, you can create an input toggle helper that will be the printer status, and then create an automation that will turn it on or off based on the conditions mentioned earlier.
- If you are comfortable using YAML, you can create a trigger-based binary template sensor which will essentially combine the automation and toggle helper into a single entity. You can use the
delay_offoption so that it only turns off after 30s of being below 50W. You can also use an availability template so that it goes unavailable when your Shelly goes unavailable. Or you can consider the printer OFF instead, if that’s what you want.
The issue with trigger based templates is that you can miss the trigger if it goes (for example) >50W -> Unavailable -> <50W
Many printers have an API that lets you check their current status if they're connected, or you could even just ping it to get on/off (rather than printing/idle/off)
I have similar automation for washing machine and the way it is done is that I created a simple statistics helper and used the power from the outlet as an input. Time 2 minutes. Then I take this as an automation and check when the value goes below 5W.
The 2m window is enough time when WM is in standby mode between cycles.
Then, because of the HA's way of setting the state to unknown at boot etc, I got automation states on every reset - so I've added another template binary senzor which has "average_sensor > 5" state
I react when template sensor goes from "on" to "off"
Automation trigger:
triggers:
- entity_id:
- binary_sensor.washing_machine_is_active
to: "off"
trigger: state
from: "on"
for:
hours: 0
minutes: 1
seconds: 0
mean sensor config:
My is_active template binary sensor:
{{ states('sensor.washing_machine_last_2_minutes_power')|float(0) > 5 }}
I didn't find any other option because of the HA's way of setting all states to unknown at start even tho states might be restored from the database...
that's only if you use numeric state, which I wouldn't recommend. If you use a state trigger with a trigger-based sensor, you can choose the exact behavior you desire. Here's 3 common options:
# Assume the power is zero when the power sensor is unavailable
template:
- trigger:
- platform: state
entity_id: sensor.shelley_power
binary_sensor:
- name: Printer Power State
state: "{{ trigger.to_state.state | float(0) > 50 }}"
delay_off: "0:00:30"
# Change to unavailable when the power sensor is unavilable
template:
- trigger:
- platform: state
entity_id: sensor.shelley_power
binary_sensor:
- name: Printer Power State
state: "{{ trigger.to_state.state | float > 50 }}"
delay_off: "0:00:30"
availability: "{{ trigger.to_state.state | is_number }}"
# Ingore the unavailable state
template:
- trigger:
- platform: state
entity_id: sensor.shelley_power
not_to: unavailable
binary_sensor:
- name: Printer Power State
state: "{{ trigger.to_state.state | float > 50 }}"
delay_off: "0:00:30"