MQTT payload filtering - PAJ7620 gesture sensor and automation

Hello!
Got PAJ7620 gesture sensor under Tasmota. It sends via MQTT:

MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:05","PAJ7620":{"Up":1}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:08","PAJ7620":{"Down":1}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:12","PAJ7620":{"Up":1}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:15","PAJ7620":{"Up":2}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:18","PAJ7620":{"Up":3}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:35","PAJ7620":{"Right":1}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:41","PAJ7620":{"Up":1}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:42","PAJ7620":{"Up":2}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:43","PAJ7620":{"Up":3}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:44","PAJ7620":{"Up":4}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:45","PAJ7620":{"Up":5}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:50","PAJ7620":{"Down":1}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:54","PAJ7620":{"Near":1}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:29:57","PAJ7620":{"Far":1}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:30:00","PAJ7620":{"Far":2}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:30:03","PAJ7620":{"Near":1}}
MQT: tele/tasmota_XXXXXB/SENSOR = {"Time":"2025-03-25T18:30:06","PAJ7620":{"Far":1}}

so, there is timestamp then sensor data: detected gesture and gesture count.
Created HA sensor template:

mqtt:
  sensor:
    - name: "MQTT_PAJ7620"
      state_topic: "tele/tasmota_XXXXXB/SENSOR"
      value_template: "{{ value }}"

which allows me read “{“Time”:“2025-03-25T18:30:06”,“PAJ7620”:{“Far”:1}}” data.

My question is: what sensor template construction should be, which allow to “extract” PAJ7620 raw data - detected gesture and gesture count? My plan is to use gestures in automations.

Regards!

I tested the following automation using your data and confirmed it reports the correct values.

alias: gestures example
triggers:
  - trigger: mqtt
    topic: tele/tasmota_XXXXXB/SENSOR
conditions: []
actions:
  - variables:
      k: "{{ trigger.payload_json.PAJ7620.keys() | list | first }}"
      v: "{{ trigger.payload_json.PAJ7620[k] }}"
  - choose:
      - conditions: "{{ k == 'Up' }}"
        sequence:
          # your actions for Up go here
          # example
          - action: notify.persistent_notification
            data:
              title: Up
              message: "{{ v }}"
      - conditions: "{{ k == 'Down' }}"
        sequence:
          # your actions for Down go here
          # example
          - action: notify.persistent_notification
            data:
              title: Down
              message: "{{ v }}"
      - conditions: "{{ k == 'Near' }}"
        sequence:
          # your actions for Near go here
          # example
          - action: notify.persistent_notification
            data:
              title: Near
              message: "{{ v }}"
      - conditions: "{{ k == 'Far' }}"
        sequence:
          # your actions for Far go here
          # example
          - action: notify.persistent_notification
            data:
              title: Far
              message: "{{ v }}"
      - conditions: "{{ k == 'Right' }}"
        sequence:
          # your actions for Right go here
          # example
          - action: notify.persistent_notification
            data:
              title: Right
              message: "{{ v }}"
      - conditions: "{{ k == 'Left' }}"
        sequence:
          # your actions for Left go here
          # example
          - action: notify.persistent_notification
            data:
              title: Left
              message: "{{ v }}"
    default:
      # your actions for unknown commands go here
      # example
      - action: notify.persistent_notification
        data:
          title: Unknown {{ k }}
          message: "{{ v }}"

Modify the value of topic to represent your actual MQTT topic and then test it to confirm it creates a notification each time a gesture is detected. This example sends notifications but that’s just for testing/demonstration purposes. You will add whatever actions you need for each gesture.

1 Like

Work perfect, THANKS :slight_smile:

1 Like