Improve efficiency of script to reduce GUI lag?

Hello, i have setup my AC to be controlled from my HA with a IR blaster. However it has maybe 60 different combination which has made the script massive however it runs smoothy every time the automation runs it. Except when I open the script in the GUI which makes everything run very slowly making it almost impossible to make any changes.

I need the script to check the temperature, mode & fan setting, but I feel I could improve on this to maybe not make it check for every option and optimize it. Thanks

P.S i had to upload the script on to pastebin as it was over the limit on here

https://pastebin.com/G7A2wu7F

Kind regards.

Would it be possible to make something like this?

service: remote.send_command
data:
  device: AC
  command: >
    {% set command = {
    "temperature": states('input_number.temperature'),
    "mode": states('input_select.mode'),
    "fan": states('input_select.fan')
    } %}
    {{command.temperature}},{{command.mode}},{{command.fan}} 
target:
  entity_id: remote.wi_fi_universal_remote_remote

Where is would get the everything and get something like 17,Cool,High which would be the same as the command? However I dont know how to integrate it into the command as it gives an error now.

Remotes speak binary (or hex converted to binary) so what you send here will not work.
You need to decode what the IR signals is composed of and how each part needs to be changed.

So I would still need a condition checker for every option, then send out the correct IR command?

The problem with that is that I need a checker for temperature, mode & fan which gives me “17,Cool,Low,” which makes my script have over 100 condition.

The command the IR sends is,

"17,Cool,Low": 

which it translates to

JgDKAIuUEDcQExA3ERMPFA8UDxUPNw83ERQPFg0UEDcQExAUEBIOFhA2ERMQFA8VDhUPFBESEDcOOQ83EDcPOBA2ETYRNw82ETcPOA83EDYOOg83EDcQFA83EBQQNhAVDzcPNxAUD66NlBATEDgPExE3EDgPNhA2DxQRFQ43EDcQNxATEDcPOA83EDcQFQ04EDcPOA84DzcQOA8TEBQPFA8UERQPEw8VDxQQExAUDhUQExATERMQFA4WDjkOExA3EBQQNxATERMQNhAADQU

I know.
I saw a thread where one actually solved/decoded the codes.
I’ll see if I can find it later, a bit busy at the moment.

Did you have any luck finding the thread? Do you remember some keywords, then i’ll can try some digging myself :slightly_smiling_face:

Just looking at your script, yes, you can simplify that with a template. The end of your script doesn’t make sense to me so I removed it. But this should completely replace your current script aside from the chooses at the bottom where ‘mode’ is missing.

ac:
  alias: AC
  variables:
    mode: "{{ states('input_select.mode') }}"
    fan: "{{ states('input_select.mode') }}"
    temperature: "{{ states('input_number.temperature') }}"
  sequence:
  - service: remote.send_command
    target:
      entity_id: remote.wi_fi_universal_remote_remote
    data:
      device: AC
      command: "{{ temperature }},{{ mode }},{{ fan }}"

This is assuming that the script you posted above works. If it doesn’t work… you can make a map of commands, but you can’t use a comma. Just use an _ instead and put temperature last.

ac:
  alias: AC
  variables:
    commands:
      cool_low_17: JgDKAIuUEDcQExA3ERMPFA8UDxUPNw83ERQPFg0UEDcQExAUEBIOFhA2ERMQFA8VDhUPFBESEDcOOQ83EDcPOBA2ETYRNw82ETcPOA83EDYOOg83EDcQFA83EBQQNhAVDzcPNxAUD66NlBATEDgPExE3EDgPNhA2DxQRFQ43EDcQNxATEDcPOA83EDcQFQ04EDcPOA84DzcQOA8TEBQPFA8UERQPEw8VDxQQExAUDhUQExATERMQFA4WDjkOExA3EBQQNxATERMQNhAADQU
      cool_low_18: ....
      ...
      cool_high_30: ....

    mode: "{{ states('input_select.mode') | lower }}"
    fan: "{{ states('input_select.mode') | lower }}"
    temperature: "{{ states('input_number.temperature') | int }}"
    command: "{{ mode }}_{{ fan }}_{{ temperature }}"
    ir_command: "{{ commands.get(command) }}"
  sequence:
  - condition: template
    value_template: "{{ ir_command is not none }}"
  - service: remote.send_command
    target:
      entity_id: remote.wi_fi_universal_remote_remote
    data:
      device: AC
      command: "{{ ir_command }}"

Sorry, I forgot about this.

Here is the thread:

Oh yeah this is something im looking for, how would I go about to add this to my Hass setup? I’ve tried to add it to my script.yaml and as well to automation but I cant get it to save and work.

Ive never used templated so im a bit at a loss here.