Shelly PLUS i4 Wall Switch Example Automation

Just posting an initial sample of automation created to use the different actions that can be created using a Shelly PLUS i4 with wall controller.

- id: '1647025690449'
  alias: Shelly Wall Button 1
  description: 'Automation for Shelly PLUS i4 Wall Actions'
  trigger:
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: single_push
    subtype: button1
    id: shelly-example-button-a-1-single-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: single_push
    subtype: button2
    id: shelly-example-button-a-2-single-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: single_push
    subtype: button3
    id: shelly-example-button-a-3-single-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: single_push
    subtype: button4
    id: shelly-example-button-a-4-single-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: double_push
    subtype: button1
    id: shelly-example-button-a-1-double-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: double_push
    subtype: button2
    id: shelly-example-button-a-2-double-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: double_push
    subtype: button3
    id: shelly-example-button-a-3-double-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: double_push
    subtype: button4
    id: shelly-example-button-a-4-double-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: long_push
    subtype: button1
    id: shelly-example-button-a-1-long-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: long_push
    subtype: button2
    id: shelly-example-button-a-2-long-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: long_push
    subtype: button3
    id: shelly-example-button-a-3-long-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: long_push
    subtype: button4
    id: shelly-example-button-a-4-long-push
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: btn_down
    subtype: button1
    id: shelly-example-button-a-1-btn-down
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: btn_down
    subtype: button2
    id: shelly-example-button-a-2-btn-down
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: btn_down
    subtype: button3
    id: shelly-example-button-a-3-btn-down
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: btn_down
    subtype: button4
    id: shelly-example-button-a-4-btn-down
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: btn_up
    subtype: button1
    id: shelly-example-button-a-1-btn-up
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: btn_up
    subtype: button2
    id: shelly-example-button-a-2-btn-up
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: btn_up
    subtype: button3
    id: shelly-example-button-a-3-btn-up
  - platform: device
    device_id: 6e9c4105160ef89fc6300d9fea855a1b
    domain: shelly
    type: btn_up
    subtype: button4
    id: shelly-example-button-a-4-btn-up
  condition: []
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-1-single-push
      sequence:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.example_light_tunable_white
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-1-double-push
      sequence:
      - service: light.turn_on
        data:
          color_temp: '{{ state_attr(''light.example_light_tunable_white'', ''color_temp'')|int
            + 50}}'
        target:
          entity_id: light.example_light_tunable_white
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-1-long-push
      sequence:
      - service: light.turn_on
        data:
          brightness_step_pct: 5
        target:
          entity_id: light.example_light_tunable_white
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-2-single-push
      sequence:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.example_light_tunable_white
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-2-double-push
      sequence:
      - service: light.turn_on
        data:
          color_temp: '{{ state_attr(''light.example_light_tunable_white'', ''color_temp'')|int
            - 50}}'
        target:
          entity_id: light.example_light_tunable_white
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-2-long-push
      sequence:
      - service: light.turn_on
        data:
          brightness_step_pct: -5
        target:
          entity_id: light.example_light_tunable_white
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-3-single-push
      sequence:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.example_light_rgb
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-3-double-push
      sequence:
      - service: light.turn_on
        data:
          hs_color:
          - '{{ (30 + (state_attr(''light.example_light_rgb'', ''hs_color'')[0]
            or 0)) % 360 }}'
          - 100
        target:
          entity_id: light.example_light_rgb
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-3-long-push
      sequence:
      - service: light.turn_on
        data:
          brightness_step_pct: 5
        target:
          entity_id: light.example_light_rgb
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-4-single-push
      sequence:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.example_light_rgb
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-4-double-push
      sequence:
      - service: light.turn_on
        data:
          hs_color:
          - '{{ (30 - (state_attr(''light.example_light_rgb'', ''hs_color'')[0]
            or 0)) % 360 }}'
          - 100
        target:
          entity_id: light.example_light_rgb
    default: []
  - choose:
    - conditions:
      - condition: trigger
        id: shelly-example-button-a-4-long-push
      sequence:
      - service: light.turn_on
        data:
          brightness_step_pct: -5
        target:
          entity_id: light.example_light_rgb
    default: []
  mode: parallel

Single Click is Toggle
Double Click Change Colour / Colour Temp +/-
Long Press is Brightness +/-

I have also mapped btn_down & btn_up but need to figure out best way to use them.

3 Likes

How did you set up the Shelly i4? I’m not able to see the buttons after integrating.

1 Like

Log into the shelly click on each input and change it to button

2 Likes

I can’t get double_push to show up in my logs.
It triggers single_push and double_push (along with btn_up and btn_down) but not double_push.

Does it work for you?

Double push is working for me use it to change colours. Have you confirmed this on the shelly itself, also are you running latest firmware on the i4, just checking

You have to enable entityes in HA. They are disabled by default.

2 Likes

1. Shelly Plus I4 settings: Select input button/switch mode: Switch

2.1 Add integration in Home Assistant
2.2 Show hidden sensors. For each sensor, set them as Enabled

Now payload.event.new_state.state can be ON or OFF. If you want payload.event.click_type:

3. Shelly Plus I4 settings: Change Select input button/switch mode to Button

2 Likes

Perfect! Thank you very much for sharing @ashp, I’ve just built my first home assistant automation using YAML based on your example and got everything working as desired.

I have changed the settings on the shelly i4 to type ‘button’ instead of switch and manually re-wrote the config while testing each step. Fantastic, thank you.

1 Like

Thanks bbccdd,

This is why I’ve uploaded this, I wanted to end up with a blueprint but needed a starting basis, I would have ended up with too many single automations if I had not discovered trigger id’s and choose conditions based on trigger id’s with this I folded down all my separate automations into a single automation entry that runs parallel actions based on the trigger so 1 automation per device with multi actions. The idea here is that you can have as many Shelly Plus i4’s and have a single automation for each that works for each shelly module you own like an i3 or a 2.5 or an i4.

Do share the love!
ashp

Thanks for the feedback here guys. However I’m confused, when I change the button type to switch, the 4 binary sensors appear. However, when I put them back to button, they disappear, and in turn I then can’t use them in HA. Any idea why this is the case? I had a Shelly i3 that worked perfectly, but I cannot get any success with the new Plus i4.

Thanks in advance.

When I get a chance I will change my buttons back to switches and check the behaviour but from what I understand is when set to switch they work as a regular binary sensor and you get on/off states (have to enable the entities, possibly re-add the shelly to HA if changing from button to switch), the automation I posted will most likely not suit this setup and your probably looking to have the presses as triggers and they only offer a single gesture/input, I would start with a fresh new automation and link the button to a light for example. you can use the trigger-id’s and chose actions to group four actions per a shelly i4. That way you only need a single automation for all 4 buttons.

Hi ashp et all,

I am not able to follow your instructions. I have the same behaviour as pgrogan wrote: as soon as I change to Button-Mode, I am no longer able to see or activate the four inputs. Switch-Mode is working perfectly.

Therefore, I tried to read the inputs via MQTT, but also there I have some strange issues. If I create a sensor like this:

- platform: mqtt
  name: "Rolladenschalter Büro Ab"
  state_topic: 'Rolladenschalter_Buero/events/rpc'
  value_template: >- 
      {% if ('input:0') and ('single_push') in value %}   
        {{'single'}}
      {% elif ('input:0') and ('double_push') in value %}   
        {{'double'}}
      {% elif ('input:0') and ('long_push') in value %}   
        {{'long'}}
      {% elif ('input:0') and ('btn_up') in value %}   
        {{'OFF'}}
      {% else %}
        {{ states('binary_sensor.Rolladenschalter_Buro_Ab') }}
      {% endif %}

the states are detected perfectly, but as soon as I add the sensor for the other three inputs, the four sensors are always synchronized. That makes me crazy… All the four inputs do always get the same state, even if they are not pushed at all. Here one real example:

- platform: mqtt
  name: "Rolladenschalter Büro Ab"
  state_topic: 'Rolladenschalter_Buero/events/rpc'
  value_template: >- 
      {% if ('input:0') and ('single_push') in value %}   
        {{'single'}}
      {% elif ('input:0') and ('double_push') in value %}   
        {{'double'}}
      {% elif ('input:0') and ('long_push') in value %}   
        {{'long'}}
      {% elif ('input:0') and ('btn_up') in value %}   
        {{'OFF'}}
      {% else %}
        {{ states('binary_sensor.Rolladenschalter_Buro_Ab') }}
      {% endif %}
      
- platform: mqtt
  name: "Rolladenschalter Büro Auf"
  state_topic: 'Rolladenschalter_Buero/events/rpc'
  value_template: >- 
      {% if ('input:2') and ('single_push') in value %}   
        {{'single'}}
      {% elif ('input:2') and ('double_push') in value %}   
        {{'double'}}
      {% elif ('input:2') and ('long_push') in value %}   
        {{'long'}}
      {% elif ('input:2') and ('btn_up') in value %}   
        {{'OFF'}}
      {% else %}
        {{ states('binary_sensor.Rolladenschalter_Buro_Auf') }}
      {% endif %}

This code will end up in two sensors

  • Rolladenschalter_Buro_Ab

  • Rolladenschalter_Buro_Auf

which are always in the same state: either both are off, single, double or long… Maybe someone see a misktake.

Thanks in advance.
Michael

hey moffmann,

I’m not using mqtt events but the principle/logic should be the same,

Could you please tell me if you see the events in logging: -

also are you able to use the trace features for debugging automations?

hope this points you in the right direction?

Regards,
Ash

I found the solution for my problem! If the Shelly Plus i4 is set to Button-Mode, the inputs will disappear as sensors within the device settings. However, it is still possible to define the corresponding triggers in an automation. The trick is you need to select Device as trigger, then select the entityname of your Shelly i4 and then you will be served with five actions per input: Single, Double, Long, Button down, Button up.

So… no need to search for the sensors or looking where to activate them.

1 Like

I wonder if you could explain this more please?

I have an i4 set up. Works fine in Shelly. Button or Switch neither do anything

A copy of what I have added is below. The shelly is seen but pressing buttons does not result in the trigger firing and neither can I get to see the double press / long press options.

Thank you for your help

I think this is an issue with the i4 device, if i subsribe to my MQTT broker i don`t get any topic updates other than

{"src":"shellyplusi4-0cdc7ef68dec","dst":"shellyplusi4-0cdc7ef68dec/events","method":"NotifyStatus","params":{"ts":1656333365.22,"input:3":{"id":3,"state":false}}}

This event update is caused by the setting

RPC status notifications over MQTT:
or
Generic status update over MQTT: 

I think the device is not yet ready for MQTT because TCPdump on the broker also seems to giving a little of information (at least not during button push)

I know this may be painful to get resolved, I would get in contact with shelly/allterco robotics who can support you for MQTT

try their KB: - Shelly API MQTT

let me know if you need further help with this!

Ticket Status: Open

Dear Sir/Madam,


Thank you for reaching us!

The Uni device is closing a contact, but the i4 is a trigger device and does not have switches.

We hope that clarifies the query.



Kind regards,
Shelly Support Team

I don’t get it you’ve inquired about a shelly i4 it’s a gen2 device, no need to mention uni device, it should be fully capable

please try the device ip: - with the folowing url

http://ip-address-of-shelly/rpc/MQTT.GetStatus

I’ve managed to get mqtt connected but i’m not at home to test