Can I do this? input.set.value from helper value

**Overarching Objective: **
Two heat sources - mini split heat pumps and an oil furnace. Heat pumps are primary heat source unless an outside air temperature threshold is crossed then they shut down and the oil furnace becomes the primary heat source. While the heat pumps are primary the oil furnace set point is below the heat pump to establish the primary/secondary relationship. As I am working with Mini Splits, the automation also needs to control for cooling.

Temperatures are controlled thru a number of helpers:
Climate - Heating Temperature
Climate - Heating Setback Temperature
Climate - Cooling Interior Target

Objective:
I attempting to set up a thermometer setback during sleeping hours. In doing this I want to establish a single value to pass to the devices as the “Climate - Target Temperature”.

Steps to date
I have a working automation that effectively manages the heat pump mode and furnace interaction based on exterior temperature.

Challange of the moment
I have created “Climate - Target Temperature” as a helper and am attempting to set its value in an automation without success using input.set.value from templated value from one of the other helpers (Climate - Heating Temperature or Climate - Heating Setback Temperature for heating and Climate - Cooling Interior Target for cooling).

The automation below runs but does not update “Climate - Target Temperature”.

Automation yaml

alias: Climate - Adjust Target Temperature
description: ""
trigger:
  - platform: state
    entity_id:
      - schedule.thermostat_setback
condition: []
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: not
                conditions:
                  - condition: state
                    entity_id: input_select.heat_pump_status
                    state: Cool
        sequence:
          - if:
              - condition: state
                entity_id: schedule.thermostat_setback
                state: "off"
            then:
              - service: input_number.set_value
                data: value:input_number.heating_temperature
                target:
                  entity_id: input_number.climate_target_temperature
            else:
              - service: input_number.set_value
                data:
                  value: input_number.heating_setback_temperature
                target:
                  entity_id: input_number.climate_target_temperature
      - conditions:
          - condition: state
            entity_id: input_select.heat_pump_status
            state: Cool
        sequence:
          - service: input_number.set_value
            data:
              value: input_number.heat_pumps_cooling_interior_target
            target:
              entity_id: input_number.climate_target_temperature
mode: single

Can I do this - if so, what have I errored on?

I think your syntax for calling the service is incorrect. Here the way I call it.

    - service: input_number.set_value
      data_template:
        entity_id: input_number.newwell_last
        value: "{{ states('sensor.newwell_last_2') }}"

In your service calls, you are doing this:

value: input_number.heating_setback_temperature

That’s not the correct way to set the value option to the current state value of the input_number. Use the states() function like this:

value: "{{ states('input_number.heating_setback_temperature') }}"

Reference: Templating States


There’s also a syntax error here :

                data: value:input_number.heating_temperature
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                      All of this should be on the next line 

Thanks to both of you.

Working code:

alias: Climate - Adjust Target Temperature
description: "Establish a thermometer setback during sleeping hours. Automaticly adjust a single value to pass to the devices as the “Climate - Target Temperature”"
trigger:
  - platform: state
    entity_id:
      - schedule.thermostat_setback
condition: []
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: not
                conditions:
                  - condition: state
                    entity_id: input_select.heat_pump_status
                    state: Cool
        sequence:
          - if:
              - condition: state
                entity_id: schedule.thermostat_setback
                state: "off"
            then:
              - service: input_number.set_value
                data_template:
                  entity_id: input_number.climate_target_temperature
                  value: "{{ states('input_number.heating_temperature') }}"
            else:
              - service: input_number.set_value
                data_template:
                  entity_id: input_number.climate_target_temperature
                  value: "{{ states('input_number.heating_temperature') }}"
      - conditions:
          - condition: state
            entity_id: input_select.heat_pump_status
            state: Cool
        sequence:
          - service: input_number.set_value
            data_template:
              entity_id: input_number.climate_target_temperature
              value: "{{ states('input_number.heat_pumps_cooling_interior_target') }}"
mode: single

It’s completely unnecessary to convert your service calls to this format:

              - service: 
                data_template:
                  entity_id:
                  value: 

In fact, the data_template option was deprecated, many versions ago, in favor of data. Your automation was failing not because you used the new format:

              - service: 
                target:
                  entity_id:
                data:
                  value: 

It was failing because you didn’t supplied the value option with correct information.

What corrects the problem is simply providing value with the state of the input_number (changing the service call to an outdated format isn’t part of the solution).

    - service: input_number.set_value
      target:
        entity_id: input_number.climate_target_temperature
      data:
        value: "{{ states('input_number.heating_temperature') }}"

Thanks again.

Alternative working code without the deprecated format (and a corrected value for the setback helper):

alias: Climate - Adjust Target Temperature 0.a
description: >-
  Establish a thermometer setback during sleeping hours. Automaticly adjust a
  single value to pass to the devices as the “Climate - Target Temperature”
trigger:
  - platform: state
    entity_id:
      - schedule.thermostat_setback
condition: []
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: not
                conditions:
                  - condition: state
                    entity_id: input_select.heat_pump_status
                    state: Cool
        sequence:
          - if:
              - condition: state
                entity_id: schedule.thermostat_setback
                state: "off"
            then:
              - service: input_number.set_value
                target:
                  entity_id: input_number.climate_target_temperature
                data:
                  value: "{{ states('input_number.heating_temperature') }}"
            else:
              - service: input_number.set_value
                target:
                  entity_id: input_number.climate_target_temperature
                data:
                  value: "{{ states('input_number.heating_setback_temperature') }}"
      - conditions:
          - condition: state
            entity_id: input_select.heat_pump_status
            state: Cool
        sequence:
          - service: input_number.set_value
            target:
              entity_id: input_number.climate_target_temperature
            data:
              value: "{{ states('input_number.heat_pumps_cooling_interior_target') }}"
mode: single
1 Like

If you’re interested, your automation can be reduced to a single service call employing a templated value option.

alias: Climate - Adjust Target Temperature 0.a
description: >-
  Establish a thermometer setback during sleeping hours. Automaticly adjust a
  single value to pass to the devices as the “Climate - Target Temperature”
trigger:
  - platform: state
    entity_id: schedule.thermostat_setback
condition: []
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.climate_target_temperature
    data:
      value: >
        {% if is_state('input_select.heat_pump_status', 'Cool') %}
          {{ states('input_number.heat_pumps_cooling_interior_target') }}
        {% else %}
          {{ states(iif(is_state('schedule.thermostat_setback', 'off'), 'input_number.heating_temperature', 'input_number.heating_setback_temperature')) }}
        {% endif %}
mode: single

If you want to confirm the value template works properly, copy-paste the following into the Template Editor:

{% if is_state('input_select.heat_pump_status', 'Cool') %}
  {{ states('input_number.heat_pumps_cooling_interior_target') }}
{% else %}
  {{ states(iif(is_state('schedule.thermostat_setback', 'off'), 'input_number.heating_temperature', 'input_number.heating_setback_temperature')) }}
{% endif %}
2 Likes