Appdaemon example for deCONZ to control Sonos (#6133)

* deCONZ - Appdaemon example control Sonos

Appdaemon example on how to control a Sonos system using an Ikea Trådfri remote

* Minor changes
This commit is contained in:
Robert Svensson 2018-09-01 11:08:09 +02:00 committed by Fabian Affolter
parent c45ead8a01
commit 9d7a1dfbb1

View File

@ -118,9 +118,9 @@ For the IKEA Tradfri remote, 1 is the middle button, 2 is up, 3 is down, 4 is le
## {% linkable_title Examples %}
### {% linkable_title Step up and step down input number with wireless dimmer %}
### {% linkable_title YAML %}
#### YAML
#### {% linkable_title Step up and step down input number with wireless dimmer %}
{% raw %}
```yaml
@ -171,15 +171,17 @@ automation:
```
{% endraw %}
#### Appdaemon
### {% linkable_title Appdaemon %}
#### {% linkable_title Appdaemon remote template %}
{% raw %}
```yaml
remote_control_living_room:
remote_control:
module: remote_control
class: RemoteControl
event: deconz_event
id: dimmer_switch_3
id: dimmer_switch_1
```
```python
@ -204,3 +206,53 @@ class RemoteControl(hass.Hass):
self.log('Button off')
```
{% endraw %}
#### {% linkable_title Appdaemon remote template %}
Community app from Teachingbirds. This app uses an Ikea Tradfri remote to control Sonos speakers with play/pause, volume up and down, next and previous track.
{% raw %}
```yaml
sonos_remote_control:
module: sonos_remote
class: SonosRemote
event: deconz_event
id: sonos_remote
sonos: media_player.sonos
```
{% endraw %}
{% raw %}
```python
import appdaemon.plugins.hass.hassapi as hass
class SonosRemote(hass.Hass):
def initialize(self):
self.sonos = self.args['sonos']
if 'event' in self.args:
self.listen_event(self.handle_event, self.args['event'])
def handle_event(self, event_name, data, kwargs):
if data['id'] == self.args['id']:
if data['event'] == 1002:
self.log('Button toggle')
self.call_service("media_player/media_play_pause", entity_id = self.sonos)
elif data['event'] == 2002:
self.log('Button volume up')
self.call_service("media_player/volume_up", entity_id = self.sonos)
elif data['event'] == 3002:
self.log('Button volume down')
self.call_service("media_player/volume_down", entity_id = self.sonos)
elif data['event'] == 4002:
self.log('Button previous')
self.call_service("media_player/media_previous_track", entity_id = self.sonos)
elif data['event'] == 5002:
self.log('Button next')
self.call_service("media_player/media_next_track", entity_id = self.sonos)
```
{% endraw %}