State unavailable

Hello all,

I am very new to HA.

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?

Thank you very much for your response.

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: []

Thank you for your reaction.
But if the printer becomes unavailable again, I still get a message. Or am I wrong?

Sorry, I got mixed up.
This is not correct.

Let me try to find my old configuration, to see how i solved this issue.

Thank you very much for your response.

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

1 Like

OK,
thank you,
go try it tomorrow i :grinning:

Thank you very much, this was really what I needed! :ok_hand: :ok_hand: :ok_hand:

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.

@valvex, I see you posted two blocks of code:

- 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 %}

and

alias: HP Printer Black
description: ''
trigger:
  - platform: state
    entity_id: sensor.hp_printer_ink_status
    from: ok
    to: low

Can you please tell me where these two blocks of code go? I thought they both go in the config.yaml file, but that doesn’t work.

Thanks!