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
225 stars 85 forks source link

Shelly Gen 1, mqtt can't setup state topic #133

Closed zylxpl closed 1 year ago

zylxpl commented 1 year ago

Trying to create blueprint for mqtt switch that publish physical state under topic: shellies/+/input/0 and shellies/+/input/1 as payload 0 or 1. Verified multiple times that the topic name is correct: image. However , for some reason Switch Manager is not recognizing this topic no matter what i try. What is even more strange, when i set up mqtt topic for a switch with #, fe shellies/shellyswitch25-xxxxxxxxxxxx/# i can see messages in debug consoles from all other topics associated with this switch (/relay, /input_event, /temperature etc) but not for input/0 or input/1 .

MQTT documentation for this switch: https://shelly-api-docs.shelly.cloud/gen1/#shelly2-5-mqtt

name: Shelly 2.5 MQTT
service: Shelly
event_type: mqtt
mqtt_topic_format: shellies/+/input/#
buttons:
  - x: 110
    y: 123
    width: 66
    height: 66
    conditions: "{{ data.topic_basename == '0' }}"
    actions:
      - title: init
        conditions:
          - key: payload
            value: "1"
      - title: hold (released)
        conditions:
          - key: payload
            value: "0"
Sian-Lee-SA commented 1 year ago

Firstly, conditions: "{{ data.topic_basename == '0' }}" is redundant and does not need to be there.

Second, the payload are integers, try removing the qoutes from the value

zylxpl commented 1 year ago

This is only part of the code, as this device have two switches, second one is using conditions: "{{ data.topic_basename == '0' }}". Anyway, i try to set up it with only 1 switch, setting exact topic name and removing conditions, no difference. Also tried without quotes, same result. What is strange, when i set topic like shellies/shellyswitch25-xxxxxxxxxxxx/# in mqtt tool, i can see messages coming to /input/0 and /input/1 topics, but if i set up the same in Switch Manager cant find anything in debug console (but every other topic pops there).

Sian-Lee-SA commented 1 year ago

When the device is discovered it will have a static topic, so a blueprint will always be either /input/0 or /input/1 (not both although the readme does have an option to include sub topics which you'll need to define). Generally, the mqtt_topic_format is just a helper for autodiscovery. Did you define the topic manually (from creating a switch) to see if that works? for example set the topic to shellies/shellyswitch25-xxxxxxxxxxxx/input/0.

If that fails, just send me a dump off the MQTT for shellies/shellyswitch25-xxxxxxxxxxxx and its sub topics and I'll try to figure it out.

zylxpl commented 1 year ago

Yes, i did exactly that, and it was not working. How can i create mqtt dump?? Also, i was experimenting with sub topic setting, but could not understand how it exactly suppose to work. Where do i need to define subtopics?

Sian-Lee-SA commented 1 year ago

Easiest way is just get mqtt explorer and just screen shot the topics. I will put the subtopic stuff in and send you an example blueprint once I get it working.

Also if your shelly device had already been added to HA then there are blueprints that uses the event bus instead of MQTT

zylxpl commented 1 year ago

image Is this enough? Can't use event bus, as my shelly device's are only connected to ha via mqtt (they are in separate locations)

Sian-Lee-SA commented 1 year ago

Could you please update Switch Manager to v1.2.1 as I found a bug that would've been causing you the issues.

The following example should get you going.

name: Shelly 2.5 MQTT
service: Shelly
event_type: mqtt
mqtt_topic_format: shellies/+/input
mqtt_sub_topics: true
buttons:
  - conditions: 
      - key: topic_basename
        value: "1"
    actions:
      - title: init
        conditions:
          - key: payload
            value: 1
      - title: hold (released)
        conditions:
          - key: payload
            value: 0

Take note of mqtt_sub_topics: true. This means that your set topic should be shellies/shellyswitch25-xxxxxxxxxxxx/input and the sub topics from there will automatically be handled by the blueprint.

Also I have tested this with variations of both endpoints (0 and 1) and payloads (0 and 1) which was working correctly.

Edit: It could also work with the MQTT topic set to shellies/shellyswitch25-xxxxxxxxxxxx/input/+ (while also removing mqtt_sub_topics: true) but honestly, I haven't experimented enough with using sub topics as generally most MQTT devices has used a single topic for all actions