Script service call for many heat pump IR data codes

I’m having an issue getting this properly formatted.
Removed all the IR codes because they are giant

heat_pump_lounge_on:
  sequence:
    service: broadlink.send_packet_192_168_2_109
    data_template:
      packet: >
        {% if is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '75') %}
        - 'JgBMAnE1=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '19') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '20') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '21') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '22') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '23') -%}
        - '=='
        {%- elif is_state('inpu t_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '24') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '25') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '19') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '20') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '21') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '22') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '23') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '24') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '25') -%}
        - '=='
        {%- else -%}
        - '=='
        {%- endif -%}

The first ‘if’ statement is purely for formatting reasons.
If I run the above through the dev tool I get;

heat_pump_lounge_on:
  sequence:
    service: broadlink.send_packet_192_168_2_109
    data_template:
      packet: >
        - '=='

I believe the ‘>’ is causing the data to not be accepted.

For example this script will fire fine, it has no template data;

heat_pump_lounge_off:
  sequence:
    - service: broadlink.send_packet_192_168_2_109
      data:
        packet: 
          - 'blah'

Any help appreciated,
Cheers.

The only part you need to copy into the dev tool is the actual template part

        {% if is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '75') %}
        - 'JgBMAnE1=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '19') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '20') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '21') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '22') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '23') -%}
        - '=='
        {%- elif is_state('inpu t_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '24') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'off') and is_state('sensor.heatpump_temp', '25') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '19') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '20') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '21') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '22') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '23') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '24') -%}
        - '=='
        {%- elif is_state('input_boolean.heat_pump_lounge_cool', 'on') and is_state('sensor.heatpump_temp', '25') -%}
        - '=='
        {%- else -%}
        - '=='
        {%- endif -%}

What exactly is your problem here? What does not work as expected / you need help with?

~Cheers

Hi, thanks for reply.
The broadlink device will not send the IR code, I’m not sure if HA even gets to the point of contacting the device.

If I don’t use a template to decide the IR code in my script my heat pump will beep, if a go use a template no action occurs.

Cheers.

You could always set the loglevel to debug. That way you will now what gets called :slight_smile:

~Cheers

I did ‘tail /var/log/syslog -F’ which i’d assume is very similar and just followed the output.

I think it has helped but cannot confirm yet since im editing from work.

This is a failed service call using my script;

service_data=packet=- ‘JgBMAnE1ECcQJxAMEAsQDBA…’

This is a successful call using no script;

service_data=packet=[‘JgBMAnA1ECcQKA8MDw0PDA8o…’]

So i removed '- ’ and added around my IR codes.
Now using service call + my script;

service_data=packet=[‘JgBMAnE1ECcQJxAMEAsQDBAnEA…’]

I’ll be able to confirm when I get home :slight_smile: /hoping.

1 Like

Unfortunately that did not fix the issue.
Turned on the full logger but I cannot see any issue;

I can turn off the heatpump but cannot turn on, the on script is the only one with a template.
To be sure the IR codes are not at fault I swapped the codes around in the scripts and the opposite IR code fired fine using the off script.

Here is an example in the log;

17-04-04 19:07:18 INFO (MainThread) [homeassistant.helpers.script] Script heat_pump_lounge_on: Executing step call service
17-04-04 19:07:18 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=packet=['onIRcode'], service=send_packet_192_168_2_109, service_call_id=139772620513008-7, domain=broadlink>

17-04-04 19:07:20 INFO (MainThread) [homeassistant.helpers.script] Script heat_pump_lounge_off: Executing step call service
17-04-04 19:07:20 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=packet=['offIRcode'], service=send_packet_192_168_2_109, service_call_id=139772620513008-11, domain=broadlink>

They look identical but the top one (on) does nothing and the bottom (off) beeps the heat pump.
Flip the IR codes around and then I can turn the heatpump on via the off script (hope that makes sense).

I guess it really doesn’t like what im doing.

Thoughts from anyone?

Please do not use ‘[’ on your own. This usually indicates an array. You need to fix the template so the ‘[’ are getting added automatically. Sadly I am not at home right now so I can’t test this. But the words you are searching for are array and template.

Hope this helps somewhat.

~Cheers

I cheaped out and make it work a different way.
Set up each IR code as a switch within the broadlink component then used the same script but to push the entity ID for toggling the IR code switch I want. Made both the ON/OFF the same IR code.
Ugly, but works.

Quick advice. I had some trouble using the built in switches from the broadlink component. They would get switched on and off every restart of HA very fast. I used it to control my av receiver and my tv. My receiver was able to go on and off but the tv didn’t catch the off command from the switch and just stayed on.

~Cheers