Hi everyone, I hope this is helpful to someone.
I created a bluprint to trigger automations based on the sonoff R5 scene controller.
The blueprint requires that your sonoff R5 entity exists in home assistant through the HACS sonoff LAN integration, thanks to AlexxIT on github for that. The integration needs to be configured as auto (R5 is not supported in local only mode, at least to date)
The R5 also requires to be paired through the eWelink app to any of M5 smart switch, S40/S40 Lite smartplug, eWeLink-Remote gateway as a sort of bridge. (Select device in ewelink, go to it’s configs and look for subdevices option). It also requires that the “bridge” device is in a fair range and up.
Once your R5 is linked to your “Bridge” device, it should show in the HACS sonoff integration, and you can start using the blueprint.
If the above button does not work, you can manually add the blueprint.
Download the yaml file sonoff_switchman_r5.yaml and put it in your home assistant “config/blueprints/automation” folder (you may also create a folder under it and put the yaml there).
Or, copy the blow code and create a yaml file in said folder.
blueprint:
name: Sonoff R5 button actions
description: Actions for a specific Sonoff R5 button (Requires the R5 to be added using the "Sonoff LAN" HACS integration, in auto mode, will not work with local only. https://github.com/AlexxIT/SonoffLAN)
domain: automation
author: Erick Rodriguez
input:
sonoff_r5_entity:
name: R5 entity
description: Select the R5 entity.
selector:
entity:
domain: sensor
integration: sonoff
r5_button_name:
name: R5 Button
description: Select the R5 button that will trigger the automation.
selector:
select:
mode: dropdown
options:
- label: Button 1
value: button_1
- label: Button 2
value: button_2
- label: Button 3
value: button_3
- label: Button 4
value: button_4
- label: Button 5
value: button_5
- label: Button 6
value: button_6
press_action:
name: Press Action
description: Action to perform when single pressing the selected button.
default: []
selector:
action: {}
double_press_action:
name: Double Press Action
description: Action to perform when double pressing the selected button.
default: []
selector:
action: {}
hold_action:
name: Hold Action
description: Action to perform when hold pressing the selected button (this will trigger the action multiple times until the button is released).
default: []
selector:
action: {}
automation_mode:
name: Automation mode
description: Select the R5 button automation mode (https://www.home-assistant.io/docs/automation/modes/).
default: queued
selector:
select:
mode: list
options:
- queued
- single
- restart
- parallel
variables:
sonoff_r5_entity: !input 'sonoff_r5_entity'
r5_button_name: !input r5_button_name
single_trigger_state: "{{ r5_button_name }}_single"
double_trigger_state: "{{ r5_button_name }}_double"
hold_trigger_state: "{{ r5_button_name }}_hold"
event_state: "{{ trigger.event.data.new_state.state }}"
press_action: !input 'press_action'
double_press_action: !input 'double_press_action'
hold_action: !input 'hold_action'
trigger:
- platform: event
event_type: state_changed
event_data:
entity_id: !input 'sonoff_r5_entity'
action:
- choose:
- conditions:
- condition: template
value_template: "{{ single_trigger_state == event_state }}"
sequence: !input 'press_action'
- conditions:
- condition: template
value_template: "{{ double_trigger_state == event_state }}"
sequence: !input 'double_press_action'
- conditions:
- condition: template
value_template: "{{ hold_trigger_state == event_state }}"
sequence: !input 'hold_action'
mode: !input automation_mode
Hopefully it works for you.
Update:
I also created a blueprint that works similarly but it would create a single automation to configure all buttons actions instead of having one automation per button of the R5.
Pro: This blueprint permits defining a single automation to control all actions of all the buttons in the R5
Con: You can only use a single automation mode for all actions (queued, parallel, single, restart)