Sensor state 'unknown' not working

Hello,

Little backstory. I have connected my Inkbird BBQ temperature meter through MQTT.

Now I tried to create a automation which will let me set a temperature via a input field, and then compare the current temperature and if equal or higher then it will for e.g turn on a light.

Now I’ve ran into the following issue, if the temperature meter is off, it says unknown but somehow this does not work as a condition in my automation:

My condition for checking state:

 - condition: template
    value_template: '{% if is_state(''sensor.inkbird_bbq_probe_1'', ''unknown'') -%}
      {{ False }} {% else %} {{ True }} {% endif %}'

My condition for the temperature (works as far as i know):

  - condition: template
    value_template: '{{ state_attr(''sensor.inkbird_bbq_probe_1'', ''temperature'')
      | float >= states(''input_number.temperature_bbq_probe1'') | float }}'

If I try this in Developer tools → template. It will return false. But when I put this in a automation it will always go to the action trigger (turn on light).

If tried several things, also with states, is_state, etc. Not working.
What am I missing here?

My full automation:

- id: '1619724184688'
  alias: Temperature probe 1 max
  description: ''
  trigger:
  - platform: time_pattern
    seconds: /5
  condition:
  - condition: template
    value_template: '{% if is_state(''sensor.inkbird_bbq_probe_1'', ''unknown'') -%}
      {{ False }} {% else %} {{ True }} {% endif %}'
  - condition: template
    value_template: '{{ state_attr(''sensor.inkbird_bbq_probe_1'', ''temperature'')
      | float >= states(''input_number.temperature_bbq_probe1'') | float }}'
  action:
  - type: turn_on
    device_id: bddee0c6664ee7991f92b574c107623a
    entity_id: light.buiten_tafel
    domain: light
  mode: single

Why not just trigger on the state?

- id: '1619724184688'
  alias: Temperature probe 1 max
  description: ''
  trigger:
  - platform: template
    value_template: "{{ state_attr('sensor.inkbird_bbq_probe_1', 'temperature') | float >= states('input_number.temperature_bbq_probe1') | float }}"
  action:
  - service: light.turn_on
    target:
      entity_id: light.buiten_tafel
  mode: single

You probably don’t even need this condition:

  condition:
  - condition: template
    value_template: "{{ not is_state('sensor.inkbird_bbq_probe_1', 'unknown') }}"

As when state_attr('sensor.inkbird_bbq_probe_1', 'temperature') is unknown the |float filter converts it to 0 which I assume will always be less than your input number set temperature.

Thanks for your response.

That’s the weird part about it, if I run this now with your value_template it still runs the automation and turns on the light.

I’ve created this template in developer tools, but this does not match:

Template:

Temperature probe: {{ state_attr('sensor.inkbird_bbq_probe_1', 'temperature') | float }}
Temperature input: {{ states('input_number.temperature_bbq_probe1') | float }}

{{ state_attr('sensor.inkbird_bbq_probe_1', 'temperature') | float >= states('input_number.temperature_bbq_probe1') | float }}

Output:

Result type: string
Temperature probe: 0.0
Temperature input: 11.0

False

Weird right? It says False but still processes the automation…

Oh wow, it’s working now. Thank you!