Creating a MQTT remote with sonoff/Tasmota and a LFN IR sensor

Whoo! Fun thing to to - but i still need help

the parts costs less then 9$ and you can (later when it works) trigger an automation, light or what ever.
buuut - its not working yet

when you comment out the condition part its triggering the automations, all of them…
I need a idea how to listen to the data part

all in packages/pack_1.yaml

automation:
  - alias: "Handle IR Commands"
    trigger:
      - platform: mqtt
        topic: 'tele/+/RESULT'
       condition:
        - condition: template      # the seperation isnt provided fufufu
          value_template: "{{ value_json.IrReceived is defined }}"
    action:
      - event: sonoff_ir
        event_data_template:
          name: irhandler
          topic: "{{ trigger.topic }}" # This will allow you to tell between the Sonoffs ;)
          protocol: '{{ value_json.IrReceived["PROTOCOL"] }}'
          bits: '{{ value_json.IrReceived["BITS"] }}'
          data: '{{ value_json.IrReceived.DATA }}'

  - alias: "Remote Button 1"
    trigger:
      - platform: event
        event_type: sonoff_ir
        event_data:
           topic: 'tele/sonoff2/RESULT'
           data: ["B47"]
    action:
       - service: light.toggle
         data:
           entity_id: light.couch
           
  - alias: "Remote Button 2"
    trigger:
      - platform: event
        event_type: sonoff_ir
        event_data:
           topic: 'tele/sonoff2/RESULT'
           data: "80B47"
    action:
       - service: light.toggle
         data:
           entity_id: light.7

           
  - alias: "Remote Button 3"
    trigger:
      - platform: event
        event_type: sonoff_ir
        event_data:
           topic: 'tele/sonoff2/RESULT'
           data: 60B47
    action:
       - service: light.toggle
         data:
           entity_id: light.einhorn

DEBUG (MainThread) [homeassistant.components.mqtt] Received message on tele/sonoff2/RESULT: b’{“IrReceived”:{“PROTOCOL”:“SONY”,“BITS”:20,“DATA”:“80B47”}}’

automation:
  - alias: "Handle IR Commands"
    trigger:
      - platform: mqtt
        topic: 'tele/+/RESULT'
    condition:
      - platform: template
        value_template: "{{ value_json['IrReceived'] is defined }}"
    action:
      - event: SONOFF_IR
        event_data_template:
          topic: "{{ trigger.topic }}" # This will allow you to tell between the Sonoffs ;)
          protocol: "{{ value_json.IrReceived.PROTOCOL }}"
          bits: "{{ value_json.IrReceived.BITS }}"
          data: "{{ value_json.IrReceived.DATA }}"

- alias: "Remote Button 1"
  trigger:
   - platform: event
     event_type: SONOFF_IR
     event_data:
       topic: 'tele/sonoff2/RESULT'
     data: 'B47'
  action:
    - service: light.toggle
      data:
      entity_id: light.light

More hopefuly later
__
just playing around with a sonoff and tasmota.
found at my Cable box an LFN Sensor inside a old RGB lightstrip controler… Cool!

got a ir reciver running and want to turn off another light Via this incoming MQTT message -

For example - pressing the 1 on a sony DVD remote gives me.

" MQT: tele/sonoff2/RESULT = {“IrReceived”:{“PROTOCOL”:“SONY”,“BITS”:20,“DATA”:“B47”}} "

Push* Exiting

*push…

need help… i cant figure this out…

automation:
  - alias: "Handle IR Commands"
    trigger:
      - platform: mqtt
        topic: 'tele/+/RESULT'
    condition:
      - condition: template
        value_template: '{{ value_json["IrReceived"] is defined }}'
    action:
      - event: sonoff_ir
        event_data_template:
          name: irhandler__: '{{ value_json["POWER"] }}'

          topic: '{{ trigger.topic }}' # This will allow you to tell between the Sonoffs ;)
          protocol: '{{ value_json.IrReceived["PROTOCOL"] }}'
          bits: '{{ value_json.IrReceived["BITS"] }}'
          data: '{{ value_json.IrReceived["DATA"] }}'
          
FAILCODE
message on tele/sonoff2/RESULT: b'{"IrReceived":{"PROTOCOL":"SONY","BITS":20,"DATA":"80B47"}}'
2018-04-10 00:57:34 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'value_json' is undefined
{{ trigger.payload_json.IrReceived is defined }}

just took 3 years to answer :smiley:

Stumbled across this trying to figure out how to go about doing the same thing…
I figured out the issue and thought I’d put it up for the next person who stumbles across this.

I ended up with this trimmed down version:

  trigger:
  - platform: mqtt
    topic: tele/bathroomsensor/RESULT
  condition:
  - condition: template
    value_template: '{{ trigger.payload_json.IrReceived is defined }}'
  action:
  - event: tasmota_ir
    event_data:
      data: '{{ trigger.payload_json.IrReceived.Hash }}'

And now after some one uses the bidet in the bathroom the exhaust fan runs for 2 minutes. :slight_smile:

1 Like

MVP - thanks for helping!