Input number

Hello to all.
I would like to create an automation that allows me to switch on a device based on a comparison of two values. One of them is a temperature and one is a number that varies.
I set the variable number

input_number:
   camera:
    name: Camera
    initial: 27
    min: 20
    max: 30
    step: 1

I have created automation in two ways but the first does not work and the second gives an error

- id: '1631956138531'
  alias: Testina on
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.0x00158d0005343cf0_temperature
    above: input_number.camera
  condition: []
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.led_goccia
  mode: single
- id: '1631897507610'
  alias: Testina on
  description: ''
  trigger:
  - platform: template
    value_template: '{{(states('sensor.0x00158d0005343cf0_temperature')|float)>=(states('input_number.camera')|float)}}'
    condition: []
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.led_goccia
  mode: single

Help thanks

Numeric state trigger will only fire when sensor.0x00158d0005343cf0_temperature goes from below input_number.camera to above input_number.camera.

Fires when the numeric value of an entity’s state (or attribute’s value if using the attribute property, or the calculated value if using the value_template property) crosses (and only when crossing) a given threshold. On state change of a specified entity, attempts to parse the state as a number and fires if the value is changing from above to below or from below to above the given threshold.

It will probably not fire immediately after you change input_number.camera, it will have to wait until the state of sensor.0x00158d0005343cf0_temperature changes to notice that it’s above the threshold.

What error?

Error loading /config/configuration.yaml: while parsing a block mapping
in “/config/automations.yaml”, line 593, column 5
expected , but found ‘’
in “/config/automations.yaml”, line 594, column 33

In the first automation nothing happens the light does not activate even waiting for time. I would like it to turn on when the temperature is greater than the input value which varies depending on the case. Thanks

Correct … the first works

You can’t use single quotes everywhere in the second automation. Try replacing the outer ones with double quotes:

- id: '1631897507610'
  alias: Testina on
  description: ''
  trigger:
    - platform: template
      value_template: "{{(states('sensor.0x00158d0005343cf0_temperature')|float)>=(states('input_number.camera')|float)}}"
  condition: []
  action:
    - service: switch.turn_on
      target:
        entity_id: switch.led_goccia
  mode: single

Now in the configuration check ok but I have an error in the log

Logger: homeassistant.config
Source: config.py:464
First occurred: 9:17:04 (5 occurrences)
Last logged: 11:09:35

  • Invalid config for [automation]: expected float for dictionary value @ data[‘above’]. Got None. (See ?, line ?).
  • Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->condition. (See ?, line ?).

I have edited my previous post to fix indentation.

I think the first error message is from the first automation. That also has incorrect indentation. Try this:

- id: '1631956138531'
  alias: Testina on
  description: ''
  trigger:
    - platform: numeric_state
      entity_id: sensor.0x00158d0005343cf0_temperature
      above: input_number.camera
  condition: []
  action:
    - service: switch.turn_on
      target:
        entity_id: switch.led_goccia
  mode: single

Thanks but I had already changed … nothing always that mistake

Are you running a version of Home Assistant older than 2021.7? See Referencing other entities in triggers and conditions – 2021.7 release notes.

Maybe I solved … since I was performing I try I had two automations with two identical names: Testina on
Now I changed the name by correcting the "and I have no more errors. Thanks

I have another problem … with both automations I do not reach the desired result. If the sensor temperature has already exceeded the input number and the vario x turn it back on, this does not happen. I would need the checking of the two values ​​to happen constantly over a certain time so that this can always create the event.An advice?

Add a state trigger for input_number.camera and a numeric state condition (same condition as the first trigger).
This will cause the automation to run again every time you change input_number.camera and the condition is fulfilled. Is this what you want?

Exactly … but complicated for me to perform

correct

- id: '1632130266262'
  alias: Testina on
  description: ''
  trigger:
  - platform: state
    entity_id: input_number.camera
  - platform: numeric_state
    entity_id: sensor.0x00158d0005343cf0_temperature
    below: input_number.camera
  condition:
  - condition: numeric_state
    entity_id: sensor.0x00158d0005343cf0_temperature
    below: input_number.camera
  - condition: numeric_state
    entity_id: input_number.camera
    above: '20'
    below: '30'
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.led_goccia
  mode: single