Temperature Sensor 'unknown' as Trigger

I’m trying to automate a device restart when the temperature sensors reported go to ‘unknown’. Here’s the automation I currently have. It didn’t trigger to restart the device. It does cycle the switch when manually executed.

- id: '1611'
  alias: Pwsensors
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.temp_outdoor
    to: unknown
  condition: []
  action:
  - service: switch.turn_off
    data: {}
    entity_id: switch.wattbox100_outlet_11
  - delay: 00:00:30
  - service: switch.turn_on
    data: {}
    entity_id: switch.wattbox100_outlet_11
  mode: single

Maybe unknown is not a ‘real’ state and cannot be uses as trigger. Consider using a template trigger or template condition with template

{{ states('sensor.temp_outdoor') == 'unknown' }}

When viewing the sensor state under Developer Tools, unknown appears. Doesn’t this establish unknown as a ‘real’ state? I’ll change to a Template trigger with your suggested template and see what happens. Thanks.

Which integration defines sensor.temp_outdoor?

I’m using a custom component that scrapes a local web page for the value. One issue was I was using unknown instead of unavailable. I’ve added the template trigger and waiting for the device to require another reboot. Usually 12 to 18 hours.

1 Like

Can you share your automation? I’m having the same issue and also using a multiscrape custom component.

Here is what I’m using:

- id: '1611147657228'
  alias: Pwsensors
  description: ''
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.temp_outdoor'') == ''unavailable'' }}'
  condition: []
  action:
  - service: switch.turn_off
    data: {}
    entity_id: switch.wattbox100_outlet_11
  - delay: 00:00:30
  - service: switch.turn_on
    data: {}
    entity_id: switch.wattbox100_outlet_11
  mode: single

This triggers when the outdoor temp sensor goes unavailable and toggles power to the PWS observer module. I’ve been able to reduce the occurrence of unavailable data by relocating the observer module. If you can reduce the distance between the observer and PWS, it may help.

1 Like

This:

  trigger:
  - platform: template
    value_template: '{{ states(''sensor.temp_outdoor'') == ''unavailable'' }}'

Can be replaced with:

  trigger:
  - platform: state
    entity_id: sensor.temp_outdoor
    to: 'unavailable'
1 Like

Thanks Tom. I’ll make the change.

Thanks to both. Quick question why for some cases (sensors) the state is ‘unavailable’ and for others is ‘unknown’? This depends on the implementation of the integration and HA doesn’t make any conversion?

Unavailable should mean there is an issue with the integration. Unknown should mean no state update has been received from the integration since home assistant started (or the integration was reloaded) but the integration itself is working as intended as far as HA can tell.

These definitions may be misused in third party integrations or templates.

1 Like

That makes sense! Thank you for the clarification and somehow that match what I’m seeing with some sensors. I’ve learned one more today… Btw is the ‘unknown’ state case sensitive? or means the same as ‘Unknown’?
Really appreciate your kind support.

The state is unknown Lovelace will display this as 'Unknown`.

Lovelace has been programmed to make things pretty.

You should always check the actual state in Developer Tools / States.

Other examples (state, Lovelace):

not_home, Away
home, Home
on, On
off, Off

And anything with a device_class. e.g. for binary sensors on and off can be displayed as many things see https://www.home-assistant.io/integrations/binary_sensor/#device-class

1 Like

Ah… Awesome and in fact was Lovelace History states that triggered the question. It is clear now.