Shelly Smoke MQTT YAML

Hi all, hope someone can help. I use Shelly relay devices with MQTT integration. I have set most of these up using YAML I have copy pasted and modified!

I now have a Shelly Smoke detector and want to configure it with YAML but I’m struggling! I have successfully set up HA to receive messages via MQTT and I know the topic that contains the message of interest.

All I want to be able to is trigger a notification in the HA App when an Alarm message is received but not sure how the YAML needs to be written to achieve this.

Would anyone be able to advise what this should look like or have an example of Shelly Smoke YAML config please? Thanks!

Should look like this according to the docs for Gen 1. Might need splitting up to fit into your existing config:

mqtt:
  sensor:
    - name: "Shelly Smoke temperature"
      state_topic: "shellies/shellysmoke-<deviceid>/sensor/temperature"
      device_class: temperature
      unit_of_measurement: '°C'
    - name: "Shelly Smoke battery level"
      state_topic: "shellies/shellysmoke-<deviceid>/sensor/battery"
      device_class: battery
      unit_of_measurement: '%'
  binary_sensor:
    - name: "Shelly Smoke alarm"
      state_topic: "shellies/shellysmoke-<deviceid>/sensor/smoke"
      payload_on: 'true'
      payload_off: 'false'
      device_class: smoke

Then just trigger an alert off binary_sensor.shelly_smoke_alarm going on.

If yours is a Gen 2 device, the docs aren’t as clear. Install MQTT Explorer and see what topics are available.

configuration YAML… mqtt: !include mqtt.yaml (all other mqtt devices working fine)

separate yaml file for sensors…

sensor:

- name: "Smoke_Alarm"
  state_topic: "shellyplussmoke-<device_id>/event/rpc"
  unit_of_measurement: "%"
  value_template: '{{ value_json.params.mqtt.connected }}'

The JSON message I am trying to parse looks like this… I want to trigger notifications where the value received = true (just testing the setup for now)

{
    "src": "shellyplussmoke-<deviceid>0",
    "dst": "shellyplussmoke-<deviceid>/events",
    "method": "NotifyStatus",
    "params": {
        "ts": 2.22,
        "mqtt": {
            "connected": true
        }
    }
}

The message above is generated when I wake the alarm. I am using that to setup and test what I want to achieve so I don’t have to keep setting the smoke alarm off with small fires!

The actual alarm message I will need to work with later is this…

{"src":"shellyplussmoke-<deviceid>","dst":"shellyplussmoke-<deviceid>/events","method":"NotifyStatus","params":{"ts":1718011105.23,"sys":{"wakeup_reason":{"cause":"alarm"}}}}

You can’t have a unit_of_measurement with a true state. Should be a binary sensor.

Ultimately you’ll need:

value_template: '{{ value_json.params.sys.wakeup_reason.cause }}'
payload_on: 'alarm'

You don’t have to write YAML configuration, you can use Shellies Discovery Gen2 GitHub - bieniu/ha-shellies-discovery-gen2: Script that adds MQTT discovery support for Shellies Gen2 devices

Well I am confused. I have the following in my mqtt.yaml file…

binary_sensor:

- name: "Smoke_Alarm"
  state_topic: "shellyplussmoke-<deviceid>/event/rpc"
  value_template: '{{ value_json.params.sys.wakeup_reason.cause }}'
  payload_on: 'alarm_test'

and the following in automation…

- id: 'xxxxx'
  alias: Smoke Alarm Test
  description: ''
  trigger:
  - platform: mqtt
    topic: shellyplussmoke-<deviceid>/events/rpc
    payload: alarm_test
  condition: []
  action:
  - service: notify.mobile_app_whassup
    metadata: {}
    data:
      message: 'Smoke Alarm Test! '
  mode: single

and this is the message json…


{"src":"shellyplussmoke-<deviceid>",
"dst":"shellyplussmoke-<deviceid>/events",
"method":"NotifyStatus",
"params":{"ts":10.50,"sys":{"wakeup_reason":{"cause":"alarm_test"}}}}

Still doesn’t seem to be working :frowning:

The automation should trigger from the binary sensor state, not the MQTT.

You need to replace <device_id> with your actual ID if you haven’t.

Your prior post included alarm not alarm_test.

1 Like

I am still struggling and no closer to figuring out what I am doing wrong :frowning:

I can see messages are being received on Mosquito Broker when I trigger the alarm. I have run the automation manually from the UI and an app notification appears on my phone.

It seems like the payload is not being processed properly in order to trigger the automation.

Any help at all would be appreciated!

This is the topic and json message I want to trigger from (I am using false for now so I don’t have to set the alarm off to test it) …

shellyplussmoke-<device>/status/smoke:0

{"id":0,"alarm":false, "mute":false}

Configuration YAML:

binary_sensor:

- name: "Smoke_Alarm"
  state_topic: "shellyplussmoke-device/status/smoke:0"
  value_template: '{{ value_json.alarm }}'
  payload_on: "false"

Automation YAML:

- id: '1718638552636'
  alias: Smoke Alarm
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.smoke_alarm
    from:
    to: 'on'
  condition: []
  action:
  - service: notify.mobile_app_whassup
    metadata: {}
    data:
      message: 'Test! '
  mode: single

Hi, I have a similar problem. I have exactly the same YAML configuration as you (just payload_off in addition). When I display the entity, I always have “unknown” as the status, although “alarm” is clearly visible as “false” in the MQTT Explorer. Does the correct status appear for you when you check the “Smoke_Alarm” entity?