I have the following problem:
I am trying to create an automation that will notify me if the printer’s ink cartridge levels are too low. But there is a printer that constantly indicates “unavailable”. If it is available again, I get the message again that the ink is almost empty.
Is there a way that I can ensure that if the printer becomes available again, it will not send a message?
I’ve handled a similar problem in the past, by creating a template binary_sensor.
For example, create a new template binary_sensor, editing accordingly:
</s> <s>- platform: template</s> <s> sensors: </s> <s> hp_printer_low_black:</s> <s> value_template: |</s> <s> {{ states('sensor.hp_printer_black') | int < 15 }}</s> <s> Then create an automation that is triggered when your new binary_sensor goes on.
``` alias: HP Printer Low Black description: ‘’ mode: single trigger: - platform: state entity_id: binary_sensor.hp_printer_low_black from: ‘off’ to: ‘on’ condition: [] action: []
But the problem is: at 10% and at 5%
I get a message. But if the sensor is on 10% and the printer becomes unavailable, then I get another message that it has more 10%. and if he has 5% I want to get a message about this too! sorry, I am really new to HA, but I am trying to learn a lot!
Ok here it is.
It was not template binary_sensor, but a template sensor.
Here’s the example
- platform: template
sensors:
hp_printer_ink_status:
value_template: |
{% if states('sensor.hp_printer_black') == 'unavailable' %}
unavailable
{% elif states('sensor.hp_printer_black') | int < 10 %}
low
{% elif states('sensor.hp_printer_black') | int >= 10 %}
ok
{% endif %}
alias: HP Printer Black
description: ''
trigger:
- platform: state
entity_id: sensor.hp_printer_ink_status
from: ok
to: low
This handles the status changed from ‘ok’ to ‘low’, so you will only get notified once.
To handle the 5% part, probably you can create a new template sensor.
I have not used this approach in a long time, but I believe it will still work
Thank you both for such a helpful discussion! I am very close to getting some of these solutions to help me with my code, and I am hoping I could get some clarification here.