Skip to content

Suggestion to simplify the Tasmota IR command script #27

@bwarden

Description

@bwarden

I followed your guide with great success, using the uniplay IR blaster, after I finally got my makeshift pogo pins (just a strip of 7 header pins) pressed just right on the test points to flash the firmware with esptool.

Regarding the sample script you provided for your TV:

```yaml
sequence:
- variables:
power: >-
0,+9140-4420+670-465Cd+665-1625+640dEdEdC-470EdCfGfGdE-1605+660fG-1600EkEkEdCdCdC-1595CdCdCdCdCkCkEkCdEkEkEkElC-39185A-2160C
input: >-
0,+9140-4420+670-490+640-470+665-1625EdE-495Ef+660iEi+635hEhEfGhEhEhEhEhEhEhE-1630EhEfGhEfGfGfGfGfG-465GhEmGhE-1620E-39195A-2160G
volume_up: >-
0,+9140-4420+670-490+640dE-1625E-470+660g+665gHdEdEfEfEgHfEfEfEfEfE-465IfEjIgIjIjIjCjI-1600HjIkIkIkC-1595CkClI-39195+9135-2160I
volume_down: >-
0,+9135-4420+670-470+665-490+640-1625+645-465+660dEdKfGfGhGhGdEhGhGhGhGhGhGhGdEjEjEjEjEjEjEjE-1600ElClElElE-1595C-39185A-2160C
mute: >-
0,+9135-4420+670-490+640-470+665-1625Ef+660fGfGdE-465GhEhEdEhEhEhEhEhEhEjGjGhEjGjCjGjCjC-1600GkGjCkCkCkG-1595C-39190+9140-2155G
menu: >-
0,+9135-4420+665-495+640-470C-1625EfC-490EfCf+660fIgEgEfCgEgEgEgEgEgEgEgEgE-465CjCgEjCjCjCjCjCgEgEjC-1620E
vizio: >-
0,+9130-4420+665-490+640-470+660-1625EdEdEdEdEfGhEhEdEhEhEhEhEhEhEfGhEhEfGhEfCfGfChEfC-465ChEfChE-1620E-39190+9135-2160C
channel_up: >-
0,+9130-4420+665-490+640dE-1625EdEdEdE-470+660gHfEfEgCfEfEfEfEfE-465Ci+670-460CgCgCgCiCiC-1600ClClClJlClClC-1595C-39185+9135-2160C
channel_down: >-
0,+9135-4420+670-490+640-470+660-1625E-465GdE-495EfGf+665hEhEdEhEhEhEhEhEhEfGfKfKfKfGfKfGfKhEhEhEhEhEhE-1620E-39190A-2190E
arrow_up: >-
0,+9140-4420+670-490+640dE-1625E-470+660dEdEgHdEfEfE-475HfEfEfEfE-1630EfEiHfEg+665gK-465KfElKlKfElKfEfE-1600HlK-1595K
arrow_down: >-
0,+9135-4420+670-470+660dE-1625+640dEdE-495GdE-490GfGfGiGfGfGfGfGfGdEfGfGdEd+665dJfGdJfGdJdJfGfGfGdJ-1620G
arrow_left: >-
0,+9135-4420+670-470+665-490+640-1625GdE-465CfGfGiEhGhGdEhGhGh+645-1620GhGhGhGhGiCiEiEkGdEdEiEiEhG-1630+635hGd+660kG
arrow_right: >-
0,+9140-4420+670-490+640dE-1625EdE-470+660dEdEdEfEfEgHfEfEfEfEfEdEg+665gIfEgIgIfEgIfEfEfE-465IfEfEjC-1600H
back: >-
0,+9140-4420+670-470+665dE-1625+640-490GhGdEd+660dIfGfGhGfGfGfGfGfGdIfGdEfGdEdEfGdEfGdEfG-465EfGfGdE-1620G-39185+9135-2185G
exit: >-
0,+9140-4420+670-490+640dE-1620E-470+665g+660gHgHgH-1625EjEgHjEjEjEjE-1630Ej+645-460H-465H-1600InHnHoHnHnHoCoHnCoHoHnC-1595H-39190+9135-2160H
guide: >-
0,+9140-4420+670-490+640dE-1625EdEdE-470+665dEdEfEfEg+660fEfEfEfEfEgHdEfEfEfEgHgIgHfEf+645-465IgHgHfEfEfE-39190+9135-2185E
ok: >-
0,+9135-4420+670-465+660-490+640-1625G-470+665iEfGfGfGhGhGiEhGhGhGhGhGiJiJhGdJdJdJhGdJhGhGdJ-1600JkJkJdC-1595C-39190A-2160J
pause: >-
0,+9135-4420+665-490+640-470C-1625EfCfC-465CfCfCgEgEhCgEgE-1630+635gEgEgE-1605+660-1600ChCmCmCh+670hNhChNhCmChChCmC-1595N-39185A-2160N
play: >-
0,+9135-4420+670-465+665-490+640-1625G-475+660fGfG-480+650fGhGhGfGhGhGhGhGhGh+645-1620G-470EfGhGhGoEoJoEoEhGhGdEoEhGnG-39185A-2165E
ffwd: >-
0,+9135-4420+670-490+640dE-1625EdE-470+660dEdEg+665fEfEgHfEfEfEfEfEgIfE-1630+635-465IfEfElIlIfE-460CmIfElIlI-1600I-1595I-39190A-2160I
rwd: >-
0,+9135-4420+670-490+640dE-1625EdEdE-470+665dEdEfEfEg+660fEfEfEfEfEfEdEfEgIfEfEgHgHgHfEgHfE-465HgHfE-1620E-39185A-2190E
stop: >-
0,+9135-4420+665-470C-490+640-1625FeFdCeFd+660eFgFgFdCgF-1620FgFgFgFdCdCdCdHgFgFdCdCgFgFgFgFdCdCgFiF-39185A-2185F
amazon: >-
0,+9140-4420+670-490+640-470+660-1625EdEdEf+665dEdEhEhEfIhEhEhEhEhEfIhE-465ChEjIhE-1600IkIkIjIkIjCkIjIjI-460I-39190A-2155I
netflix: >-
0,+9135-4420+670-490+640dE-1625EdE-470+660gHgHg+665fEfEgHfEfEfEfEfEfEfEgIfEgIfEfEfEgIgIfEgIfEgI-465IjI-39190+9140-2165H
iheartradio: >-
0,+9135-4420+670-470+660dE-1625+640d+665dHdHdH-465HfGfGiHfGfGfGfGfGiHfG-1630G-1600HiHkHkHkHkHiCiHiHkHiHiC-460H-39190A-2160H
enter: >-
0,+9145-4420+670-490+640dE-1625E-470+665dEg+660-495EdEfEfE-465HfEfEfEf+645-1620EkHfEkHfEfEfEkHkC-1600HkHnHkCkCkCnH-1595H-39190+9140-2160H
num_space: >-
0,+9140-4420+670-490+640-495E-1625E-470+660dEh+665hJdEgEgEhIgEgEgEgEgEgEgEgEgEgEgE-1630EgEhJhJ-465JlJlJlJlJ-460C-39190A-2160C
num_1: >-
0,+9140-4420+670-470+665-490+640-1625GfGdEfGfG-495GhG-1630+635fGhGhGhGhGhGhGdEd+660dEhGdEdE-465EdEh+645-1620GhGdEhGhGoG
num_2: >-
0,+9140-4420+670-490+640-470+665-1625EdEdEdEdE-495EhE-1630EfGhEhEhEhEhEfGhE-465GfGhEkGfGf+660hEfGhEhEkGhEhE-1620E-39190A-2165G
num_3: >-
0,+9140-4420+670-490+640-470+665-1625EdEdEdEfGfGhEhEf+660hEhE-1630EhEhEhEhE-465GkGhEkGkGkCkGkG-1600GlGkClGlC-1595G-39180A-2160G
num_4: >-
0,+9140-4420+670-490+640dE-1625EdEdEdE-470+660gHfEfEg+665fEfEfEfEfE-465IjIfEjIfEjCjCjC-1600IkIjCkIjIkIkI-1595C-39190+9135-2160I
num_5: >-
0,+9135-4420+670-490+640dE-1625EdEdE-495E-470+665dEfEfEhIfEfEfEfEfEfE-465IfEhIfEjIjIjIjC-1600IjIkIjIkCkI-1595I-39190+9130-2160C
num_6: >-
0,+9140-4420+665-495+640-490E-1625EfEfEfE-470Ch+660-1630EgEhCgEgEgEgEgEhCgEgE-465CgEhChChC-1600CkCk+670lCkClClC-1595C-39185+9135-2160C
num_7: >-
0,+9135-4420+665-490+640dE-1625E-495EdEdEdEdEfEfEdEfEfEfEfEfEfEfEfE-470CfEhC-465CiCiCiChCfEiCfEfE-1620E-39190A-2160C
num_8: >-
0,+9130-4420+670-470+660dE-1625+640dEdE-490GdE-465+665fGfGiJf+645-1620GfGfGfGiJiJiJfG-1600EiJiJiJmJmJmJiJiJmJmJmJ-39185+9135-2160J
num_9: >-
0,+9140-4420+670-490+640dE-1625+645dEdEdE-470+665dEfEfEh+660fEfEfEfEfEfEhIhIfE-1630E-465IhIlIhIfEfElIlC-1600ImI-1595I-39185A-2160I
num_0: >-
0,+9135-4420+670-490+640-470+660-1625EfGdEdEfGfGhEhEfGhEhEhEhEhEdEf+665dEfGhE-465IfIfIhEhEhEhEfIhEhE-1620E-39185+9140-2185E
- choose:
- alias: Power
conditions:
- condition: template
value_template: '{{ command == ''power'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ power }}'
- alias: Input
conditions:
- condition: template
value_template: '{{ command == ''input'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ input }}'
- alias: Volume Up
conditions:
- condition: template
value_template: '{{ command == ''volume_up'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ volume_up }}'
- alias: Volume Down
conditions:
- condition: template
value_template: '{{ command == ''volume_down'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ volume_down }}'
- alias: Mute
conditions:
- condition: template
value_template: '{{ command == ''mute'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ mute }}'
- alias: Vizio
conditions:
- condition: template
value_template: '{{ command == ''vizio'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ vizio }}'
- alias: Channel Up
conditions:
- condition: template
value_template: '{{ command == ''channel_up'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ channel_up }}'
- alias: Channel Down
conditions:
- condition: template
value_template: '{{ command == ''channel_down'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ channel_down }}'
- alias: Arrow Up
conditions:
- condition: template
value_template: '{{ command == ''arrow_up'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ arrow_up }}'
- alias: Arrow Down
conditions:
- condition: template
value_template: '{{ command == ''arrow_down'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ arrow_down }}'
- alias: Arrow Left
conditions:
- condition: template
value_template: '{{ command == ''arrow_left'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ arrow_left }}'
- alias: Arrow Right
conditions:
- condition: template
value_template: '{{ command == ''arrow_right'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ arrow_right }}'
- alias: Back
conditions:
- condition: template
value_template: '{{ command == ''back'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ back }}'
- alias: Exit
conditions:
- condition: template
value_template: '{{ command == ''exit'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ exit }}'
- alias: Guide
conditions:
- condition: template
value_template: '{{ command == ''guide'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ guide }}'
- alias: OK
conditions:
- condition: template
value_template: '{{ command == ''ok'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ ok }}'
- alias: Pause
conditions:
- condition: template
value_template: '{{ command == ''pause'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ pause }}'
- alias: Play
conditions:
- condition: template
value_template: '{{ command == ''play'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ play }}'
- alias: Fast Forward
conditions:
- condition: template
value_template: '{{ command == ''ffwd'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ ffwd }}'
- alias: Rewind
conditions:
- condition: template
value_template: '{{ command == ''rwd'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ rwd }}'
- alias: Stop
conditions:
- condition: template
value_template: '{{ command == ''stop'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ stop }}'
- alias: Amazon Video
conditions:
- condition: template
value_template: '{{ command == ''amazon'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ amazon }}'
- alias: Netflix
conditions:
- condition: template
value_template: '{{ command == ''netflix'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ netflix }}'
- alias: I Heart Radio
conditions:
- condition: template
value_template: '{{ command == ''iheartradio'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ iheartradio }}'
- alias: Enter
conditions:
- condition: template
value_template: '{{ command == ''enter'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ enter }}'
- alias: Number Pad Space
conditions:
- condition: template
value_template: '{{ command == ''num_space'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_space }}'
- alias: Number Pad 1
conditions:
- condition: template
value_template: '{{ command == ''num_1'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_1 }}'
- alias: Number Pad 2
conditions:
- condition: template
value_template: '{{ command == ''num_2'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_2 }}'
- alias: Number Pad 3
conditions:
- condition: template
value_template: '{{ command == ''num_3'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_3 }}'
- alias: Number Pad 4
conditions:
- condition: template
value_template: '{{ command == ''num_4'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_4 }}'
- alias: Number Pad 5
conditions:
- condition: template
value_template: '{{ command == ''num_5'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_5 }}'
- alias: Number Pad 6
conditions:
- condition: template
value_template: '{{ command == ''num_6'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_6 }}'
- alias: Number Pad 7
conditions:
- condition: template
value_template: '{{ command == ''num_7'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_7 }}'
- alias: Number Pad 8
conditions:
- condition: template
value_template: '{{ command == ''num_8'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_8 }}'
- alias: Number Pad 9
conditions:
- condition: template
value_template: '{{ command == ''num_9'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_9 }}'
- alias: Number Pad 0
conditions:
- condition: template
value_template: '{{ command == ''num_0'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ num_0 }}'
- alias: Menu
conditions:
- condition: template
value_template: '{{ command == ''menu'' }}'
sequence:
- service: mqtt.publish
data:
topic: '{{ mqtttopic }}'
payload: '{{ menu }}'
default: []
fields:
command:
description: IR Command Alias
example: power_on
mqtttopic:
description: MQTT Topic for Tasmota IR blaster
example: cmnd/irblaster/IRSend
mode: single
icon: mdi:remote
alias: Remote - Vizio TV
```

It can be simplified a great deal by setting the individual IR command payloads in a single dictionary, indexed by command, then using a single templated service call like this:

jvc_tv:
  alias: Remote - JVC TV
  icon: mdi:remote
  mode: single
  fields:
    command:
      description: IR Command Alias
      example: power_on
    mqtttopic:
      description: MQTT Topic for Tasmota IR blaster
      example: cmnd/irblaster/IRSend
  sequence:
  - variables:
      commands:
        power: '{"Protocol":"JVC","Bits":16,"Data":0xC0E8,"Repeat":10}'
        hdmi: '{"Protocol":"JVC","Bits":16,"Data":0xC0A8}'
        input: '{"Protocol":"JVC","Bits":16,"Data":0xC0C8}'
        mute: '{"Protocol":"JVC","Bits":16,"Data":0xC038}'
        volume_down: '{"Protocol":"JVC","Bits":16,"Data":0xC0F8}'
        volume_up: '{"Protocol":"JVC","Bits":16,"Data":0xC078}'
        enter: '{"Protocol":"JVC","Bits":16,"Data":0xC050}'
  - service: mqtt.publish
    data:
      topic: '{{ mqtttopic }}'
      payload: '{%if command in commands %}{{ commands[command] }}{% endif %}'

If the command isn't in the dictionary, Tasmota will harmlessly warn about an empty payload to IRSend. Obviously, you could still use your preferred raw payloads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions