How to detect a sensor with "unknown" state

Hi Guys, I have a sensor that a random intervals stop working and Home Assistant reports state “unknown”. I can send a reboot, which solves the problem, but in order to automate it I must detect when the sensor reports “unknown”. There is a side problem, because if I print the state with “states.potencia_ac.state”, it reports “Desconocido” ( I am spanish).
I am trying a template lik the following one , but it does not work

      {% if is_state("sensor.potencia_ac", "unknown") %}
        Roto
      {% else %}
        no roto
      {% endif %}

Can somebody help me?

Look in the developer tools /states menu and find the sensor. It’s real state (before translation?) will be reported there.

The state in the states list of the developers tools is “unknown”

Then that is the state you should use.

You have pasted code for a sensor but it sounds like you want an automation.

trigger:
  platform: state
  entity_id: sensor.potencia_ac
  to: 'unknown'
action:
[do your reboot here...]
1 Like

It seems that this trigger works; I’ve configured it to send a notification instead of the reboot, and if I change manually the state to ‘unknown’ in the states tool, the message is sent.
Thanks a lot.
eHc

I supplied the solution but you marked your post as the answer. Kind of uncool.

I am sorry; it is my first post and did not know the rules.
Thanks for pointing it up; I’ve changed it.
eHc

2 Likes