Can you explain the input number integration in terms a beginner can understand

I have a couple of roller blind switches for which HA reports state ‘unknown’. This is correct: the switches aren’t designed to report state. They don’t know the state of the blind: the blind does.

If the blind is open and I send the switch an open command, the switch will close the up-circuit for 30 seconds. Nothing will happen but a click, because the blind knows it is already up.

This behaviour is expected because the switches are emulating traditional mechanical switches that have 2 toggles (up/stop and down/stop) but in electrical effect only 3 different positions: up, down, and stop. The switch closes either the up power circuit or the down power circuit and it is up to the blind to open the power circuit again when the roller reaches its upper or lower limit.

What I want to do is emulate the state by having a persistent variable somewhere that gets set to “open” after an automation sends an open command, and gets set to “closed” after an automation sends a close command. I realize that an arrangement like that can get out of step with reality, for instance if someone simply closes the blind by pressing the button. I’m prepared to live with that. It will only be wrong for half a day.

But I don’t know how to go about creating and using a variable like that. I’ve read the documentation about the Input number integration, but that documentation assumes that all I need is unexplained sample code, with no attempt to explain what the example code does.

Given the problem statement above, with a single variable that can have two values, 0 and 1, how do I go about coding this?

Since you want “a single variable that can have two values”, I would recommend an Input Boolean instead of an Input number. That would make it easier to use within the normal syntax used in HA automations where “on” normally denotes “open” and “off”, “closed”.

Input numbers or booleans entities can be created either in your configuration.yaml file using YAML (as shown in the docs you mentioned), or in the UI through the Helpers dashboard. If you decide to do it using YAML, you must restart HA in order for the new configuration to be loaded and the new entities to be created.

Once created, the entities can be used in State triggers and conditions or as entity targets for their related actions (1, 2). Since they cannot be attached to a device, you will not find them in the Automation editor under the Device triggers/conditions/actions.

Yes, the documentation assumes you have read and understood the prior documentation topics like the entire Getting Started section and Automation section. Note that when I say “section” I mean all the articles listed in the left-hand column, not just the landing page those links take you to.

All of the example I see on the Input Number integration page include brief explanations either as article text or as comments within the YAML examples.


Keep in mind that there are a number of other options…

Personally, I would probably get a window/door sensor to attach to the blinds so their state could actually be known to HA then set up Template covers.

Hi,

You can create a input_text helper and set the value of it in the “Open” and “Close” automation.

I just read the official documentation for the Input Number integration and each example contains an explanation for what it does.

Here’s how to set the value of an Input Number to 1. I adapted it from one of the examples in the documentation. It employs the input_number.set_value action.

action: input_number.set_value
target:
  entity_id: input_number.blinds
data:
  value: 1

I assume you will be creating an automation to set the state of the blinds. If the YAML example I posted is unclear, simply use the Automation Editor in its default Visual mode and select the action (Input Number - Set Value) from the menus (no knowledge of YAML is required).

If all you want to do is show a blind with its position in the UI there is already a built in to do exactly what you want a: Template Cover

Unfortunately with no feedback loop you will need to run it in optimistic mode - which can only be configured through Yaml (there is no option in the GUI), anyway the Yaml would look something like this:

template:
  - cover:
      - name: Kitchen Blind
        optimistic: true
        device_class: blind
        open_cover:
          - action: switch.turn_on
            target:
              entity_id: switch.kitchen_blind_open
        close_cover:
          - action: switch.turn_on
            target:
              entity_id: switch.kitchen_blind_close

You will need to edit the actions to suit your needs.


If you want to be able to stop the blind you will need an input boolean to record the last action taken (so you can send the same action again) in which case you won’t need to run in optimistic mode since you can reuse the boolean to define the state.

Hence we need to:

  • Remove the optimistic line.
  • Define the state
  • Add additional actions to update the input boolean when open_cover or close_cover actions run.
  • Define a stop_cover action that uses the boolean to determine which action to (re)send.
template:
  - cover:
      - name: Kitchen Blind
        state: "{{ iif(is_state('input_boolean.kitchen_blind_open', 'on'), 'open', 'closed') }}"
        device_class: blind
        open_cover:
          - action: input_boolean.turn_on
            target:
              entity_id: input_boolean.kitchen_blind_open
          - action: switch.turn_on
            target:
              entity_id: switch.kitchen_blind_open
        close_cover:
          - action: input_boolean.turn_off
            target:
              entity_id: input_boolean.kitchen_blind_open
          - action: switch.turn_on
            target:
              entity_id: switch.kitchen_blind_close
        stop_cover:
          - if:
              - condition: state
                entity_id: input_boolean.kitchen_blind_open
                state:
                  - "on"
            then:
              - action: switch.turn_on
                target:
                  entity_id: switch.kitchen_blind_open
            else:
              - action: switch.turn_on
                target:
                  entity_id: switch.kitchen_blind_close

Note: Because we no longer need to be “optimistic” it is possible to define the above automation through the UI.