Number template - what am I doing wrong?

Hi I have some problems getting a number template to work.

template:
  - number:
        name: number test
        state: "{{ states('input_number.just_input_number') }}"
        min: 0
        max: 100
        step: 1
        set_value:
          - action: input_number.set_value
            target:
              entity_id: input_number.just_output_number
            data:
              value: "{{ (value - 1.5) * 2 }}"

When I change “just_input_number”, then “number_test” is updated but the action to set the value of “just_output_number” is never executed. I thought I had followed the example here exactly (it looks like it is trying to do similar, ie update another number) , but it still doesn’t work as expected.

No messages in the logs that I can find either. My actual example is a little different as I am trying to set a timer on a heater based on the difference between setpoint and actual temperature, but this is a simpler example that still wont work for me.

I am on 2024.12.0, I tried with 2024.11.3 too.

Thanks for any help.

No one? I think i should write this up as a bug report?

Normally, your action in set_value would be targeted at just_input_number… otherwise the state of number_test will never match the values you set it to.

That is the expected behavior. The actions in set_value are only triggered when number_test itself is changed.

Are you sure you even want a template number? They have a very niche use case. Perhaps a trigger-based template sensor with an actions section is what you really need.

If you’re not sure, describe your use case in more detail and we can help. Your brief description just sounded like you needed an automation.

my number_test gets changed when the entity in the state template gets changed. It doesn’t trigger the action.

I tried template number because it cuts down on having to have a template and an automation to adjust my heater.

The use case is:

Bathroom heated by
    electric towel rail with zwave switch
    underfloor heating with zwave room thermostat 
    the towel rail (160W) by itself is usually enough to keep the bathroom above 23C so the floor never gets warm ! (

When the bathroom floor is heating, the PWM value (https://github.com/domectrl/ha-slow_pwm) is adjusted in proportion to the difference between setpoint and room temperature to give some power to the towel rail

I have already solved this with an input_number and an automation, but it should have worked with the number template.

Is anyone interacting with the input_number (e.g. via a dashboard) or is it only the automation that is changing the input_number?

If you share your automation I bet we can get you back to a single entity. Or if you’ve identified a bug, that would be useful too.

Yes, that is the expected behavior.

The entity used in the state template is not the input, it is the storage place. The input is the number entity which is created by the configuration. Only script or dashboard actions targeted at number.number_test will trigger the action sequence configured under set_value… So the value of entity used in the state template must be updated within set_value to remain accurate.

Here is an example that simulates what I am trying to do. It should be standalone so you can just drop it into a HA instance.

Use this code in configuration.xml:

  input_number:
      just_input_number:
        name: Input number
        initial: 30
        min: 0
        max: 100
        step: 1
      just_output_number:
        name: Output number
        initial: 30
        min: 0
        max: 600
        step: 1
    
    template:
      - number:
          - name: towel test
            state: "{{ states('input_number.just_input_number') }}"
            min: 0
            max: 100
            step: 1
            set_value:
              - action: input_number.set_value
                data:
                  value: >-
                     {{ (value + 100) * 2 }}
                target:
                  entity_id: input_number.just_output_number

You may also add this card to your dashboard:

    type: entities
    entities:
      - input_number.just_input_number
      - number.towel_test
      - input_number.just_output_number

image

My expectation is that any changes to towel_test will trigger a call to set_value and changes to just_input_number will as such trigger a change to just_output_number

What happens is:

  • changes to just_input_number currently updates towel_test but not just_output_number

  • changes to towel_test using the slider currently updates just_output_number

If this behaviour is “by design” then there is not much point surely?

That does not make sense, I cant see that it is useful as you can just do the same with a regular automation. As I understand the documentation, a change in state should trigger set_value?

“This example demonstrates the usage of a template number with a unit of measurement set to change a unit-less value of another number entity.”

So when the cutting height changes their automower_cutting_height_raw gets changed

You are misunderstanding some part of it.

In the referenced example, the change in state of number.automower_cutting_height_raw will change the current value shown as the state of number.automower_cutting_height, but it will not trigger set_value… and it doesn’t need to because the target of the action is already at the desired height.

Yes, when number.automower_cutting_height is changed by script or dashboard action, the action sequence of set_value will run and the value of the targeted entity number.automower_cutting_height_raw will be changed.

Ok, the clarification helped a bit. It seems I can achieve what I want with a simple state trigger:

template:
  - trigger:
      - trigger: state
        entity_id: input_number.just_input_number
    action:
      - action: input_number.set_value
        data:
          value: >-
             {{ ((states('input_number.just_input_number')|int) + 100) * 2 }}
        target:
          entity_id: input_number.just_output_number

I wasn’t sure if a state trigger could be added to my previous number example, but this one is working.