How to use if/then statements to create dictionary variables in scripts

The following example assumes the variable mode is defined elsewhere in the script or has been passed to the script.

  - variables:
      setpoints:
        occupied: "{{ states('input_number.hvac_default_temp_occupied_' ~ mode) }}"
        empty: "{{ states('input_number.hvac_default_temp_empty_' ~ mode) }}"
        overnight: "{{ states('input_number.hvac_default_temp_overnight_' ~ mode) }}"
  - service: input_number.set_value
    target:
      entity_id: input_number.hvac_bedroom_setpoint
    data: 
      value: "{{ setpoints['occupied'] }}"
3 Likes