Sian-Lee-SA / Home-Assistant-Switch-Manager

Switch manager is a centralised component to handle button pushes for your wireless switches. This includes anything passed through the event bus. The component relies on switch blueprints which is easily made to allow GUI configuration of your switches and their button pushes. This helps remove clutter from the automations.
Other
257 stars 86 forks source link

mqtt, won't work when json value in []array #129

Closed zylxpl closed 1 year ago

zylxpl commented 1 year ago

Hello, trying to create blueprint for Shelly 2 PM connected via mqtt. However, values i need to use are in the [...] array in json payload, and it is not working. Sample mqtt payload:

{
    "src": "shellyplus2pm-b8d61a89b8c8",
    "dst": "shellyplus2pm-b8d61a89b8c8/events",
    "method": "NotifyEvent",
    "params": {
        "ts": 1684890281.22,
        "events": [
            {
                "component": "input:1",
                "id": 1,
                "event": "single_push",
                "ts": 1684890281.22
            }
        ]
    }
}

and my blueprint:

name: Shelly Plus 2pm mqtt
service: Shelly
event_type: mqtt
mqtt_topic_format: +/events/rpc
buttons:
  - x: 110
    y: 123
    width: 66
    height: 66
    conditions:
      - key: params.events[0].id
        value: 0
    actions:
      - title: tap
        conditions:
          - key: params.events[0].event
            value: single_push
      - title: hold
        conditions:
          - key: params.events[0].event
            value: long_push
Sian-Lee-SA commented 1 year ago

change array keys to periods instead of []. params.events.0.id

zylxpl commented 1 year ago

Thank you, works like a charm. Any interest for it to be push to master (i can also add int, double etc to normal shelly blueprints)? :

name: Shelly Plus 2PM MQTT
service: Shelly
event_type: mqtt
mqtt_topic_format: +/events/rpc
buttons:
  - x: 110
    y: 123
    width: 66
    height: 66
    conditions:
      - key: params.events.0.id
        value: 0
    actions:
      - title: init
        conditions:
          - key: params.events.0.event
            value: btn_down
      - title: press
        conditions:
          - key: params.events.0.event
            value: single_push
      - title: press 2x
        conditions:
          - key: params.events.0.event
            value: double_push
      - title: press 3x
        conditions:
          - key: params.events.0.event
            value: triple_push
      - title: hold
        conditions:
          - key: params.events.0.event
            value: long_push
      - title: hold (released)
        conditions:
          - key: params.events.0.event
            value: btn_up

  - x: 110
    y: 241
    width: 66
    height: 66
    conditions:
      - key: params.events.0.id
        value: 1
    actions:
      - title: init
        conditions:
          - key: params.events.0.event
            value: btn_down
      - title: press
        conditions:
          - key: params.events.0.event
            value: single_push
      - title: press 2x
        conditions:
          - key: params.events.0.event
            value: double_push
      - title: press 3x
        conditions:
          - key: params.events.0.event
            value: triple_push
      - title: hold
        conditions:
          - key: params.events.0.event
            value: long_push
      - title: hold (released)
        conditions:
          - key: params.events.0.event
            value: btn_up
Sian-Lee-SA commented 1 year ago

Cool glad it worked out. Feel free to PR if you wish. Adding an init to the other shelly's sounds fine although it will cause a misconfig for users who are already using that blueprint so it's not always ideal to update a blueprint once it's published from a previous release.