Turn a light on with input number

I’m trying to use an input_number helper and an automation to turn a light on. The idea is to use it as a rudimentary PIN code.

So I type in 1234. The automation then checks the number and turns the light on.

I’m doing it in the visual editor but this is the YAML

description: ""
trigger:
  - platform: numeric_state
    entity_id: input_number.passcode
    above: 1
    attribute: initial
    below: 9999
condition:
  - condition: state
    entity_id: input_number.passcode
    attribute: initial
    state: "1234"
action:
  - service: light.toggle
    data: {}
    target:
      entity_id: light.hab_light_1_light
mode: single

It’s not a surprise to me that it doesn’t work as I have no idea what I’m doing :slight_smile:

Is this actually doable? And, if so, if someone can point me at what I need to change then I’d be grateful.

You are checking the intital value attribute of the input_number in your trigger and condition. This is a value you configured when you set up the input number and it is not going to change. All it does is reset the input number to that value when home assistant is restarted or the integration is reloaded. You want to check the state of the input number, like this:

description: ""
trigger:
  - platform: state
    entity_id: input_number.passcode
    to: 1234
condition: {}
action:
  - service: light.toggle
    data: {}
    target:
      entity_id: light.hab_light_1_light
  - service: input_number.set_value
    data:
      value: 9999
    target:
      entity_id: input_number.passcode
mode: single

This will trigger when the input number changes from anything to 1234. It will then toggle the light and reset the input_number (to 9999) for the next time you want to use it.

2 Likes

Thank you for that. The only thing I had to change was the trigger on the automation so that it looks for 1234.0 rather than just 1234