Shellies Discovery Gen2 Script

Apperently nothing, i think i misunderstood how it’s supposed to work.

1 Like

Hi, can’t get entities from Shelly Plus Add-On (connected to Shelly Plus 1).
Shelly Plus 1 and all entities is discovered fine, all entities are found and visible, but there is no digital sensor entity connected to the Add-On.
I can see the readings of the digital sensor when viewing through the Shelly Plus 1 web UI, but not through MQTT.

- id: shellies_announce_gen2
  alias: "Shellies Announce Gen2"
  trigger:
    - platform: homeassistant
      event: start
  variables:
    device_info_payload:  "{{ {'id': 1, 'src':'shellies_discovery', 'method':'Shelly.GetConfig'} | to_json }}"
    device_ids:  # enter the list of device IDs (MQTT prefixes) here
      - shellyplus1-gate
  action:
    - repeat:
        for_each: "{{ device_ids }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: "{{ repeat.item }}/rpc"
              payload: "{{ device_info_payload }}"
- id: shellies_discovery_gen2
  alias: "Shellies Discovery Gen2"
  mode: queued
  max: 999
  trigger:
  - platform: mqtt
    topic: shellies_discovery/rpc
  action:
  - service: python_script.shellies_discovery_gen2
    data:
      id: "{{ trigger.payload_json.src }}"
      device_config: "{{ trigger.payload_json.result }}"

Do I understand correctly that the device doesn’t send information about the sensor to the MQTT broker?

Basically yes. On HA I can see Shelly Plus 1 relay switch entity, additional internal switch entity and so on, but not external digital sensor entity (I connected digital sensor to add-on, on/off, and it works if I look at the Shelly Plus 1 web UI).
Actually I looked at the script code and as I understand this part of the code finds only external temperature and humidity sensors, but I could be wrong:

if device_config["sys"]["device"].get("addon_type") == "sensor":
        for sensor_id in range(100, 200):
            if device_config.get(f"temperature:{sensor_id}"):
                topic, payload = get_sensor(
                    "temperature",
                    DESCRIPTION_EXTERNAL_SENSOR_TEMPERATURE,
                    sensor_id=sensor_id,
                )
                config[topic] = payload

            if device_config.get(f"humidity:{sensor_id}"):
                topic, payload = get_sensor(
                    "humidity",
                    DESCRIPTION_EXTERNAL_SENSOR_HUMIDITY,
                    sensor_id=sensor_id,
                )
                config[topic] = payload

Yes, only temperature and humidity sensors are currently supported. But… if your sensor data is not published on MQTT broker, there is no way to implement this in a script.
I need a response to the Shelly.GetConfig service and sensor state data. I can’t do anything without it.

I hope this helps:

{"ble":{"enable":false,"rpc":{"enable":true},"observer":{"enable":false}},"cloud":{"enable":false,"server":"iot.shelly.cloud:6012/jrpc"},"input:0":{"id":0,"name":null,"type":"switch","invert":false,"factory_reset":true},"input:100":{"id":100,"name":"MyDigitalSensor","type":"switch","invert":false,"factory_reset":false},"mqtt":{"enable":true,"server":"192.168.99.99:1883","client_id":"shellyplus1-gate","user":null,"topic_prefix":"shellyplus1-gate","rpc_ntf":true,"status_ntf":false,"use_client_cert":false,"enable_rpc":true,"enable_control":true},"script:1":{"id":1,"name":"shellies_discovery_gen2_script_20221116","enable":false},"switch:0":{"id":0,"name":null,"in_mode":"detached","initial_state":"off","auto_on":false,"auto_on_delay":60.00,"auto_off":false,"auto_off_delay":60.00},"sys":{"device":{"name":"shellyplus1-gate","mac":"A8032ABA2AA4","fw_id":"20230308-091529/0.14.1-g22a4cb7","discoverable":true,"eco_mode":false,"addon_type":"sensor"},"location":{"tz":"Europe/Vilnius","lat":54.690620,"lon":25.269800},"debug":{"mqtt":{"enable":false},"websocket":{"enable":false},"udp":{"addr":null}},"ui_data":{},"rpc_udp":{"dst_addr":null,"listen_port":null},"sntp":{"server":"time.google.com"},"cfg_rev":27},"wifi":{"ap":{"ssid":"ShellyPlus1-A8032ABA2AA4","is_open":true,"enable":false,"range_extender":{"enable":false}},"sta":{"ssid":"MySSID","is_open":false,"enable":true,"ipv4mode":"dhcp","ip":null,"netmask":null,"gw":null,"nameserver":null},"sta1":{"ssid":null,"is_open":true,"enable":false,"ipv4mode":"dhcp","ip":null,"netmask":null,"gw":null,"nameserver":null},"roam":{"rssi_thr":-80,"interval":60}},"ws":{"enable":false,"server":null,"ssl_ca":"ca.pem"}}
{"device_class":null,"disabled_by":null,"disabled":false,"entity_category":null,"entity_id":"binary_sensor.shellyplus1_gate_switch_100_input","icon":null,"original_device_class":"power","original_icon":null,"state":{"entity_id":"binary_sensor.shellyplus1_gate_switch_100_input","state":"off","attributes":{"device_class":"power","friendly_name":"shellyplus1-gate switch_100 input"},"last_changed":"2023-04-24T07:16:09.117936+00:00","last_updated":"2023-04-24T07:16:09.117936+00:00"},"unit_of_measurement":null}

Am I missing something? This input entity was generated by Shellies Discovery. So what is the problem?

This entity appears only when I add same Shelly Plus 1 device additionally with Shelly integration Shelly - Home Assistant
Without this Shelly integration this entity is not visible. I always thought that Shellies Discovery biggest plus is that you don’t need to use any additional integrations, or am I missing something here.

When you use Shellies Discovery, MQTT integration is used :wink:

I know that but I can’t understand why when I use Shellies Discovery+MQTT integration this entity is not visible in MQTT integration, but if I use Shellies Discovery+MQTT integration+Shelly integration this entity becomes visible in MQTT integration.

Device config entries from both integrations (MQTT and Shelly) share unique_id and Home Assistant combine those config entries into one device. You should not use two integrations for one device.

Yes, that’s why I’m asking you if it’s possible to add this sensor to discovery, next to the temperature and humidity external sensor, and I used the Shelly integration only to get the sensor state data example as you asked.

I still need sensor state data from your MQTT broker. I don’t want to guess what the device is sending.

Hope this helps:

{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyStatus","params":{"ts":1682328914.52,"input:100":{"id":100,"state":true}}}
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyStatus","params":{"ts":1682328915.27,"input:100":{"id":100,"state":false}}}
1 Like

I also need the payload of the topic shellyplus1-gate/status/input:100.

I can’t see any activity on this topic shellyplus1-gate/status/input:100 or even on this shellyplus1-gate/status/#
There is only events related with this topic: shellyplus1-gate/events/rpc

We cannot use events topic because its content is variable. Please show me all the topics/payloads that the device sends when changing the state of the sensor.

Sorry, there was some device MQTT misconfiguration. Payload of the topic shellyplus1-gate/status/input:100

Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/status/input:100', ... (24 bytes))
{"id":100,"state":false}

Full shellyplus1-gate/# topic log:

Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (156 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyStatus","params":{"ts":1682434994.20,"input:100":{"id":100,"state":true}}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/status/input:100', ... (23 bytes))
{"id":100,"state":true}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (157 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyStatus","params":{"ts":1682434994.71,"input:100":{"id":100,"state":false}}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/status/input:100', ... (24 bytes))
{"id":100,"state":false}

Thank you @vrmtm
One more question. Can you change the sensor type from switch to button (I’m not sure if it is possible for ext sensor) and show me response to Shelly.GetConfig service and payload of shellyplus1-gate/status/input:100 and shellyplus1-gate/events/rpc topics?

Sensor type button

Shelly.GetConfig:

{"ble":{"enable":false,"rpc":{"enable":true},"observer":{"enable":false}},"cloud":{"enable":false,"server":"iot.shelly.cloud:6012/jrpc"},"input:0":{"id":0,"name":null,"type":"switch","invert":false,"factory_reset":true},"input:100":{"id":100,"name":"MyDigitalInput","type":"button","invert":false,"factory_reset":false},"mqtt":{"enable":true,"server":"192.168.99.99:1883","client_id":"shellyplus1-gate","user":null,"topic_prefix":"shellyplus1-gate","rpc_ntf":true,"status_ntf":true,"use_client_cert":false,"enable_rpc":true,"enable_control":true},"script:1":{"id":1,"name":"shellies_discovery_gen2_script_20221116","enable":false},"switch:0":{"id":0,"name":null,"in_mode":"detached","initial_state":"off","auto_on":false,"auto_on_delay":60.00,"auto_off":false,"auto_off_delay":60.00},"sys":{"device":{"name":"shellyplus1-gate","mac":"A8032ABA2AA4","fw_id":"20230308-091529/0.14.1-g22a4cb7","discoverable":true,"eco_mode":false,"addon_type":"sensor"},"location":{"tz":"Europe/Vilnius","lat":54.690620,"lon":25.269800},"debug":{"mqtt":{"enable":false},"websocket":{"enable":false},"udp":{"addr":null}},"ui_data":{},"rpc_udp":{"dst_addr":null,"listen_port":null},"sntp":{"server":"time.google.com"},"cfg_rev":51},"wifi":{"ap":{"ssid":"ShellyPlus1-A8032ABA2AA4","is_open":true,"enable":false,"range_extender":{"enable":false}},"sta":{"ssid":"ShellyPlus1-A8032ABA2AA4","is_open":false,"enable":true,"ipv4mode":"dhcp","ip":null,"netmask":null,"gw":null,"nameserver":null},"sta1":{"ssid":null,"is_open":true,"enable":false,"ipv4mode":"dhcp","ip":null,"netmask":null,"gw":null,"nameserver":null},"roam":{"rssi_thr":-80,"interval":60}},"ws":{"enable":false,"server":null,"ssl_ca":"ca.pem"}}

Topic shellyplus1-gate/events/rpc (shellyplus1-gate/#):

Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (206 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492837.13,"events":[{"component":"input:100", "id":100, "event":"btn_down", "ts":1682492837.13}]}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (204 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492837.48,"events":[{"component":"input:100", "id":100, "event":"btn_up", "ts":1682492837.48}]}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (209 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492837.63,"events":[{"component":"input:100", "id":100, "event":"single_push", "ts":1682492837.63}]}}

Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (206 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492870.25,"events":[{"component":"input:100", "id":100, "event":"btn_down", "ts":1682492870.25}]}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (204 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492870.34,"events":[{"component":"input:100", "id":100, "event":"btn_up", "ts":1682492870.34}]}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (206 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492870.65,"events":[{"component":"input:100", "id":100, "event":"btn_down", "ts":1682492870.65}]}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (204 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492870.83,"events":[{"component":"input:100", "id":100, "event":"btn_up", "ts":1682492870.83}]}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (209 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492871.83,"events":[{"component":"input:100", "id":100, "event":"double_push", "ts":1682492871.83}]}}

{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492894.61,"events":[{"component":"input:100", "id":100, "event":"btn_down", "ts":1682492894.61}]}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (207 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492895.61,"events":[{"component":"input:100", "id":100, "event":"long_push", "ts":1682492895.61}]}}
Client null received PUBLISH (d0, q0, r0, m0, 'shellyplus1-gate/events/rpc', ... (204 bytes))
{"src":"shellyplus1-a8032aba2aa4","dst":"shellyplus1-gate/events","method":"NotifyEvent","params":{"ts":1682492896.25,"events":[{"component":"input:100", "id":100, "event":"btn_up", "ts":1682492896.25}]}}

After I changed the sensor type from switch to button, there is no events of topic shellyplus1-gate/status/input:100, only rpc

1 Like