Sonos / Media Player / Luuchten mat engem Taster steieren

D’Apparater vu Sonos sin eng fein Saach, just nervt mech dass ech ëmmer muss ee Smartphone /Tablet bei Hand hunn fir d’Lidder ze wiesselen oder d’Lautstäerkt anzestellen. Besonnesch bei der Spull heescht et fir d’éischt d’Hänn ofdréchnen, Handy huelen, App starten an da lass. An dësem Artikel presentéieren ech meng Léisung fir solch Aktioune mat engem eenzelen Taster ze realiséieren.

Aktiounen

Folgend Aktiounen mussen realiséierbar sinn:

  • Single Click: Play/Pause
  • Double Click: Nächst Lidd an der Queue
  • Long Press: Lautstäerkt +
  • Long Press: Lautstäerkt –

No engem Long Press soll “d’Richtung” vun der Lautstäerkt (also erop oder erof) wiesselen.

Hardware

Als Taster benotzen ech ee Wireless Zigbee Button vu Xiaomi:

Xiaomi Mijia Wireless Switch, bedriwwen mat enger CR2032 Batterie
Xiaomi Mijia Wireless Switch, bedriwwen mat enger CR2032 Batterie

Wichteg! Dësen Taster funktionéiert nëmme mat enger ZigBee Gateway!

Kontroller / Software

Dat ganz gëtt gesteiert vum HomeAssistant, mir brauchen dofir Folgendes:

  • 1 input_boolean switch; dësen definéiert op mir d’Lautstäerkt erop oder erof setzen. Wiesselt no engem “Long press”
  • 6 Automatiounen:
    • 1 fir Single Click (un/aus)
    • 1 fir Double Click (nächst Lidd)
    • 4 fir d’Lautstäerkt ze steieren, jee nom Zoustand vum input_boolean rifft eng Automatioun ee bestëmmte Skript sou laang op bis den Taster net méi gedréckt gëtt, an wiesselt dann den input_boolean
  • 2 Skripten:
    • 1 fir Lautstäerkt +
    • 1 fir Lautstäerkt –

Code

Konfiguratioun (configuration.yaml)

input_boolean:
  sonos_dim:
    name: Sonos Dim
    initial: off

Automatiounen (automations.yaml)

# Automatioun 1: Un/Aus mat Single Click
- id: '1511198265745'
  alias: Sonos Play-Pause mat Xiaomi Taster Single Click
  trigger:
  - event_data:
      click_type: single
      entity_id: binary_sensor.switch_158d0002f6e07a
    event_type: xiaomi_aqara.click
    platform: event
  action:
  - data:
      entity_id: media_player.sonos
    service: media_player.media_play_pause

# Automatioun 2: Nächst Lidd mat Double Click
- id: '1552150251690'
  alias: Sonos - Next Track Xiaomi Taster Double Click
  trigger:
  - event_data:
      click_type: double
      entity_id: binary_sensor.switch_158d0002f6e07a
    event_type: xiaomi_aqara.click
    platform: event
  condition: []
  action:
  - data:
      entity_id: media_player.sonos
    service: media_player.media_next_track

# Automatioun 3: Volume +
- id: 'sonos-volume-up-on'
  alias: Sonos Volume up on
  initial_state: 'on'
  trigger:
  - platform: event
    event_type: xiaomi_aqara.click
    event_data:
      entity_id: binary_sensor.switch_158d0002f6e07a
      click_type: long_click_press
  condition:
  - condition: state
    entity_id: input_boolean.sonos_dim
    state: 'off'
  action:
  - service: script.turn_on
    entity_id: script.20190309001

# Automatioun 4: input_boolean un no long Press fir Volume+
- id: 'sonos-volume-up-stop-bool-on'
  alias: Sonos Volume up stop - boolean on
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: binary_sensor.switch_158d0002f6e07a
    from: 'on'
    to: 'off'
  condition:
  - condition: state
    entity_id: input_boolean.sonos_dim
    state: 'off'
  action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.sonos_dim

# Automatioun 5: Volume-
- id: 'sonos-volume-down-on'
  alias: Sonos Volume down on
  initial_state: 'on'
  trigger:
  - platform: event
    event_type: xiaomi_aqara.click
    event_data:
      entity_id: binary_sensor.switch_158d0002f6e07a
      click_type: long_click_press
  condition:
  - condition: state
    entity_id: input_boolean.sonos_dim
    state: 'on'
  action:
  - service: script.turn_on
    entity_id: script.20190309002

# Automatioun 6: input_boolean aus no long Press fir Volume-
- id: 'sonos-volume-up-stop-bool-off'
  alias: Sonos Volume up stop - boolean off
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: binary_sensor.switch_158d0002f6e07a
    from: 'on'
    to: 'off'
  condition:
  - condition: state
    entity_id: input_boolean.sonos_dim
    state: 'on'
  action:
  - service: input_boolean.turn_off
    entity_id: input_boolean.sonos_dim

Skripte (scripts.yaml)

# Skript 1 : Volume +
'20190309001':
  alias: sonos-volume-up
  sequence:
  - condition: state
    entity_id: input_boolean.sonos_dim
    state: 'off'
  - service: media_player.volume_up
    entity_id: media_player.sonos
  - service: script.turn_off
    entity_id: script.20190309001
  - service: script.turn_on
    entity_id: script.20190309001

# Skript 2 : Volume -
'20190309002':
  alias: sonos-volume-down
  sequence:
  - condition: state
    entity_id: input_boolean.sonos_dim
    state: 'on'
  - service: media_player.volume_down
    entity_id: media_player.sonos
  - service: script.turn_off
    entity_id: script.20190309002
  - service: script.turn_on
    entity_id: script.20190309002

Aaner Méiglechkeeten

Dës Léisung funktionéiert grondsätzlech och mat aner media_player am Home Assistant ( zum Beispill Volumio), mee awer och als Dimmer fir Luuchten!

Als Beispill:

  • Single Click: Un/Aus
  • Long Press: Hellegkeet +
  • Long Press: Hellegkeet –

Dofir brauch een am fong nëmmen den Service Call “media_player.media_play_pause” mat “light.toggle” z’ersetzen, souwéi

  - service: media_player.volume_up
    entity_id: media_player.sonos

mat

- service: light.turn_on
  entity_id: light.luucht1_2
  data_template:
    brightness: '{{states.light.luucht1_2.attributes.brightness - 10}}'

Google Assistant

Nach op der Sich no Iddien? Op mengem Blog fënns du een Artikel wéi een de Sonos kann iwwert Google Assistant usteieren.

Permanent link to this article: https://www.hiscorebob.lu/2019/03/sonos-media-player-luuchten-mat-engem-taster-steieren/

Hannerlosst eng Noriicht:

This site uses Akismet to reduce spam. Learn how your comment data is processed.