Input number on change sends command to Broadlink / Switch reads the input number value

Hello guys,

First question:

I want control my AC using Broadlink. What I want to do is when I move the slider, the HA sends to Broadlink the IR code for that temperature.
I have the switches from Broadlink and the scripts.

My configuration.yaml

#Input number
input_number:
  target_temp:
    name: Temperatura
    min: 18
    max: 25
    step: 1
    unit_of_measurement: ºC  
  icon: mdi:target

On automations.yaml, I wrote this, but I’m getting an error:

#  - alias: Set temp slider
#    trigger:
#      platform: state
#      entity_id: input_number.target_temp
#    action:
#      service: switch.broadlink_send_packet_192_168_0_188
#      data:
#        packet: >
#          {% if is_state("input_number.target_temp", "18.0") -%}
#           - "Broadlink code 18ºC"
#          {% elif is_state("input_number.target_temp", "19.0") -%}
#           - "Broadlink code 19ºC"
#          {%- else -%}
#            #ERRO
#          {%- endif %}

I read the this topic, I tested some codes, but it didn’t worked, and the last post, I don’t understand
https://community.home-assistant.io/t/trigger-various-scripts-with-input-slider/21124/17

Second question:

I put one switch to turn my ac on and off, but when I turn it on, the temperature is send on IR code, so my question is: Can the switch read the slider, and send the slider’s temperature to the broadlink?

First, you shouldn’t use #ERRO as your else statement because you are sending nothing to packet when getting to that branch. # indicates comment which means the line will be ignored. You should supply it with the word error.

Second, you are placing a data_template inside the data section. You need to place it inside a data_template section. Templates always need to go in template sections:

  - alias: Set temp slider
    trigger:
      platform: state
      entity_id: input_number.target_temp
    action:
      service: switch.broadlink_send_packet_192_168_0_188
      data_template: # <------ CHANGED TO DATA_TEMPLATE
        packet: >
          {% if is_state("input_number.target_temp", "18.0") -%}
            Broadlink code 18ºC
          {% elif is_state("input_number.target_temp", "19.0") -%}
            Broadlink code 19ºC
          {%- else -%}
            Broadlink Error
          {%- endif %}

If you want to make a switch that sends a temperature when it turns on, you can use a template switch or tie a input_boolean to a turn on / turn off automation. Personally I recommend template switch because everything is together as a package. The only downside to template switch is that you would need to read a state from something. If you plan to use the switch to track the on/off state, you’d want to use input_boolean.

It’s been a while… And I want to reply and close.
I solved this with Smart IR.

1 Like