This is a blueprint to trigger automations using the Shelly i3 via MQTT. The native Shelly integration (for me at least) does not trigger immediately when a switch is turned on/off, but it does update properly via MQTT, which is why I have created it.
This blueprint assumes that you have set all 3 inputs to “Toggle Switch” mode (Act as a flip switch with one state for “ON” and one state for “OFF”.), NOT “Momentary” mode. This can be done on the i3’s web interface at the Input 1 / 2 / 3 menu → Settings → Button Type → Toggle Switch.
(Maybe in the future I’ll create one that uses the momentary settings. Or both. For now, it’s toggle only, because this is what I needed )
The blueprint requires an ID, which can be read from the i3’s web interface under Settings → Device Info → Device ID (eg.: E8DB48B6CADB). This is necessary to subscribe to the correct MQTT topic (Shelly i3 API documentation).
Remember: You’ll need to have your own MQTT broker set up, and both Home Assistant (MQTT Integration) and the Shelly i3 needs to use it (Shelly i3 can be set up to use MQTT from its web interface).
Note: By default the i3 sends status updates via MQTT every 30 seconds, which may result in unexpected behavior. To overwrite this so it only sends MQTT updates when one the input values have changed, you’ll need to use the API like this: http://<shelly-ip>/settings?mqtt_update_period=0
Insert the i3’s IP address, and specify your update period (for example 0
), and paste it in your browser. That’s it !
blueprint:
name: MQTT - Shelly i3 Toggle Buttons
description: Trigger actions with a Shelly i3 from MQTT in toggle mode. Remember to set your Shelly i3 to MQTT mode, and point it (and Home Assistant) to your MQTT broker. This automation only works with the switches being in toggle mode (NOT momentary).
domain: automation
# The MQTT update period cannot be set via the web interface. You have to use the REST API with the following command:
# http://<shelly-ip>/settings?mqtt_update_period=0
input:
shelly_i3_id:
name: "Shelly i3 ID"
description: "The Device ID of the Shelly i3. Can be found on the web interface of the Shelly i3 under 'Settings -> Device Info'. (Eg.: XXXXXXXXXXXX)"
selector:
text:
input_1_on:
name: Input 1 Turned On
description: I1 input has been turned on
default: []
selector:
action:
input_1_off:
name: Input 1 Turned Off
description: I1 input has been turned off
default: []
selector:
action:
input_2_on:
name: Input 2 Turned On
description: I2 input has been turned on
default: []
selector:
action:
input_2_off:
name: Input 2 Turned Off
description: I2 input has been turned off
default: []
selector:
action:
input_3_on:
name: Input 3 Turned On
description: I3 input has been turned on
default: []
selector:
action:
input_3_off:
name: Input 3 Turned Off
description: I3 input has been turned off
default: []
selector:
action:
trigger_variables:
shelly_id: !input shelly_i3_id
## Example MQTT topic full paths:
## shellies/shellyix3-98CDAC254191/input/0
## shellies/shellyix3-98CDAC254191/input/1
## shellies/shellyix3-98CDAC254191/input/2
## Topic subscription using MQTT trigger limited templates: https://www.home-assistant.io/docs/automation/trigger/#mqtt-trigger
trigger:
- platform: mqtt
topic: "{{'shellies/shellyix3-' ~ shelly_id ~ '/input/0'}}"
id: "I1"
- platform: mqtt
topic: "{{'shellies/shellyix3-' ~ shelly_id ~ '/input/1'}}"
id: "I2"
- platform: mqtt
topic: "{{'shellies/shellyix3-' ~ shelly_id ~ '/input/2'}}"
id: "I3"
condition: []
action:
choose:
- conditions:
- condition: trigger
id: I1
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.payload == "0" }}'
sequence: !input input_1_off
- conditions:
- condition: template
value_template: '{{ trigger.payload == "1" }}'
sequence: !input input_1_on
- conditions:
- condition: trigger
id: I2
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.payload == "0" }}'
sequence: !input input_2_off
- conditions:
- condition: template
value_template: '{{ trigger.payload == "1" }}'
sequence: !input input_2_on
- conditions:
- condition: trigger
id: I3
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.payload == "0" }}'
sequence: !input input_3_off
- conditions:
- condition: template
value_template: '{{ trigger.payload == "1" }}'
sequence: !input input_3_on