Use input_number as trigger in automation

Hi,

I currently have;

  • alias: Humidity Trigger On
    trigger:
    platform: numeric_state
    entity_id: sensor.humidity
    below: 50
    condition:
    condition: time
    after: ‘20:00:00’
    before: ‘06:00:00’
    action:
    • service: homeassistant.turn_on
      entity_id: switch.humidifier

But wondering if it’s possible to replace the hard coded “50” with a reference to an input_number state; so something like;

  • alias: Humidity Trigger On
    trigger:
    platform: numeric_state
    entity_id: sensor.humidity
    below: input_number.target_humidity
    condition:
    condition: time
    after: ‘20:00:00’
    before: ‘06:00:00’
    action:
    • service: homeassistant.turn_on
      entity_id: switch.humidifier

I know you can do value_template: but I’m not sure if it works with below:. try it out and see if you get any errors in the log because of it.

below: '{{ states.input_number.target_humidity.state }}'

Also, please use code blocks and syntax highlighting when posting (see the blue box at the top of the forum).

Thanks for the quick reply. Unfortunately, that didn’t work and get this error :slight_smile:

Invalid config for [automation]: expected float for dictionary value @ data['trigger'][0]['below']. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 147). Please check the docs at https://home-assistant.io/components/automation/
15:44 config.py (ERROR)

try removing the single quotes around the value template. If that doesn’t work, then you may need to go with a template trigger like this:

trigger:
  platform: template
  entity_id: sensor.humidity
  value_template: '{{ states.sensor.humidity.state < states.input_number.target_humidity.state }}'

or create a template binary sensor and use it as your trigger: https://home-assistant.io/components/binary_sensor.template/

1 Like

should be as simple as

    trigger:
      - platform: state
        entity_id: input_number.<your entity> 

then what ever condition and action you want

Would that work for my use-case ? I assume this will only trigger when I change the input_number. Rather, I need it to trigger when the reported humidity drops below the input_number.

Using the template binary sensor did the trick. Thanks for your help.

Any luck getting this to work?

yes, they got it to work. see their last post. They used a template binary sensor like what I linked to a few posts above.

1 Like

Hello!

really interested in how you did that exactly. Can you please post the code?

thank you

Look at the link I posted. They used a template binary sensor.

In the post above, where the link to how to create a binary_sensor is, the reason the template trigger did not work is because only one of the two entities used in the template was listed. Also it is comparing strings instead of first converting them to numbers. It would have worked if the entity_id line was removed and the trigger changed to:

trigger:
  platform: template
  value_template: "{{ states('sensor.humidity')|float < states('input_number.target_humidity')|float }}"
1 Like

thank you for your help.

ok now i understand why it is not working. i worked arround with binary sensor and used the state as a trigger. but this way looks much cleaner. thx

Is there a way to combine both a hard-coded pre-defined trigger number in an automation and an input_number slider to fine-tune?

I have a number of automations for triggering a humidifier relay for growing edible mushrooms - they have different humidity parameters at different growth cycles, so I would like to add an input number slider to fine tune when I happen to be growing a different species for instance.

Um, …, add??? :man_shrugging:

trigger:
  platform: template
  value_template: "{{ states('sensor.humidity')|float <
                      states('input_number.target_humidity')|float + NUMBER }}"

I have to agree with Phil, if you have a number range, set that as the input number range, then tweak the input number according to what you are growing and the stage in its growth cycle.

Though not sure why you don’t automate that as well (different cycles for different crops, started when you initialise them)

Really, that easy? I’ll implement that later then. Thanks!

…and hello again Matt! Actually, i have automated the whole thing, with the automations triggered by sensors. I just wanted to add a fine-tune tweak slider to do some minor adjustments if need be because in this case we are dealing with nature.

I couldn’t seem to find a way to add the slider with the necessary presets to the automation - as the slider is in the config.yaml. I didn’t think i could just use the same automation and add the slider too - though i still don’t understand why the trigger thresholds wouldn’t just revert back to the number hardcoded in the automation…

As i said, i’ll play with it later.

Thanks guys.

Who is Matt ?

Just use Phil’s example but knock out the ‘hard-coded’ number
so : -

trigger:
  platform: template
  value_template: "{{ states('sensor.humidity')|float < states('input_number.target_humidity') | float  }}"

Say your humidity range is (say) 60 to 90% with 0.1 resolution then set your input number as so : -

input_number:
  target_humidity:
    name: Humidity Target
    min: 60
    max: 90
    step: 0.1
    icon: mdi:water-percent

This way when you adjust the ‘humidity’ you are adjusting a ‘real world’ number, not (say) : -15
Minus 15 on what ??? you then have to remember the hard-coded and subtract 15, why make life hard ?

1 Like

Sorry, that should have read Mutt. Stupid auto correct!

I’ll play with that a bit later then and keep you posted. Thanks again.