Radiosender mit Xiaomi Cube steuern

Share on facebook
Share on twitter

Die Datei configuration.yaml enthält den folgenden Code:

# Sensoren
sensor: !include sensor.yaml

input_select:
# Cube2 welche Seite liegt oben?
  cube2_seite_oben:
    name: Cube2 Seite oben
    options:
      - seite1
      - seite2
      - seite3
      - seite4
      - seite5
      - seite6
      - shake
    initial: seite1

Ich habe die Sensoren aus der Datei configuration.yaml ausgelagert um die Übersichtlichkeit zu wahren. Angelegt habe ich dafür die Datei sensor.yaml.

# Cube2
    cube2_seite_oben:
      entity_id:
        - input_select.cube2_seite_oben
      value_template: '{{states.input_select.cube2_seite_oben.state}}'
      friendly_name: 'Cube2 Seite oben'

Das Herzstück findet sich in der automations.yaml.

- id: '1122334455021'
  alias: Cube2_Lautstärke_regeln
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: cube2
  condition:
    condition: template
    value_template: "{% set x = trigger.event.data.event|string %} {{ x|length !=\
      \ 4 or x[1:3] != '00' }}      \n"
  action:
  - service: media_player.volume_set
    entity_id: media_player.arbeitszimmer
    data_template:
      volume_level: "{% if (trigger.event.data.event > 0) and (trigger.event.data.event\
        \ | int < 2500) %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float + 0.1 }} \n{% elif (trigger.event.data.event < 0) and (trigger.event.data.event\
        \ | int > -2500) %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float - 0.1 }}          \n{% elif (trigger.event.data.event > 2501) and\
        \ (trigger.event.data.event < 4000) %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float + 0.15 }} \n{% elif (trigger.event.data.event < -2501) and (trigger.event.data.event\
        \ | int > -4000) %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float - 0.15 }}             \n{% elif (trigger.event.data.event > 4001)\
        \ and (trigger.event.data.event < 7000) %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float + 0.2 }} \n{% elif (trigger.event.data.event < -4001) and (trigger.event.data.event\
        \ | int > -7000) %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float - 0.2 }}              \n{% elif (trigger.event.data.event > 7001)\
        \ and (trigger.event.data.event < 110000) %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float + 0.3 }} \n{% elif (trigger.event.data.event < -7001) and (trigger.event.data.event\
        \ | int > -110001) %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float - 0.3 }}                    \n{% elif trigger.event.data.event >\
        \ 110001 %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float + 0.5 }}\n{% elif trigger.event.data.event < -110001 %} \n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float - 0.5 }}               \n{% else %}\n  {{ states.media_player.arbeitszimmer.attributes.volume_level\
        \ | float - 0.01 }} \n{% endif %}\n"

Um eine Aktion auszulösen (Script für den Radiosender und die Anzeige im Frontend), je nachdem, welche Seite des Würfels oben liegt und den Mediaplayer auszuschalten, wenn der Würfel geschüttelt wird:

- id: '1122334455022'
  alias: Seite1
  trigger:
  - event_data:
      id: cube2
    event_type: deconz_event
    platform: event
  condition:
  - condition: template
    value_template: '{% set valid_events = [1001, 1002, 1003, 1004, 1005, 1006] %}
      {{ trigger.event.data.event in valid_events }}

      '
  action:
  - data:
      option: seite1
    entity_id: input_select.cube2_seite_oben
    service: input_select.select_option
  - data: {}
    entity_id: script.1589712176243
    service: script.turn_on
- id: '1122334455023'
  alias: Seite2
  trigger:
  - event_data:
      id: cube2
    event_type: deconz_event
    platform: event
  condition:
  - condition: template
    value_template: '{% set valid_events = [2001, 2002, 2003, 2004, 2005, 2006] %}
      {{ trigger.event.data.event in valid_events }}

      '
  action:
  - data:
      option: seite2
    entity_id: input_select.cube2_seite_oben
    service: input_select.select_option
  - data: {}
    entity_id: script.1589712176244
    service: script.turn_on
- id: '1122334455024'
  alias: Seite3
  trigger:
  - event_data:
      id: cube2
    event_type: deconz_event
    platform: event
  condition:
  - condition: template
    value_template: '{% set valid_events = [3001, 3002, 3003, 3004, 3005, 3006] %}
      {{ trigger.event.data.event in valid_events }}

      '
  action:
  - data:
      option: seite3
    entity_id: input_select.cube2_seite_oben
    service: input_select.select_option
  - data: {}
    entity_id: script.1589712176246
    service: script.turn_on
- id: '1122334455025'
  alias: Seite4
  trigger:
  - event_data:
      id: cube2
    event_type: deconz_event
    platform: event
  condition:
  - condition: template
    value_template: '{% set valid_events = [4001, 4002, 4003, 4004, 4005, 4006] %}
      {{ trigger.event.data.event in valid_events }}

      '
  action:
  - data:
      option: seite4
    entity_id: input_select.cube2_seite_oben
    service: input_select.select_option
  - data: {}
    entity_id: script.1589712176245
    service: script.turn_on
- id: '1122334455026'
  alias: Seite5
  trigger:
  - event_data:
      id: cube2
    event_type: deconz_event
    platform: event
  condition:
  - condition: template
    value_template: '{% set valid_events = [5001, 5002, 5003, 5004, 5005, 5006] %}
      {{ trigger.event.data.event in valid_events }}

      '
  action:
  - data:
      option: seite5
    entity_id: input_select.cube2_seite_oben
    service: input_select.select_option
  - data: {}
    entity_id: script.1589712176247
    service: script.turn_on
- id: '1122334455027'
  alias: Seite6
  trigger:
  - event_data:
      id: cube2
    event_type: deconz_event
    platform: event
  condition:
  - condition: template
    value_template: '{% set valid_events = [6001, 6002, 6003, 6004, 6005, 6006] %}
      {{ trigger.event.data.event in valid_events }}

      '
  action:
  - data:
      option: seite6
    entity_id: input_select.cube2_seite_oben
    service: input_select.select_option
  - data: {}
    entity_id: script.1589712176242
    service: script.turn_on
- id: '1122334455028'
  alias: shake
  trigger:
  - event_data:
      id: cube2
    event_type: deconz_event
    platform: event
  condition:
  - condition: template
    value_template: '{% set valid_events = [7007] %} {{ trigger.event.data.event in
      valid_events }}

      '
  action:
  - data:
      option: shake
    entity_id: input_select.cube2_seite_oben
    service: input_select.select_option
  - data: {}
    entity_id: media_player.arbeitszimmer
    service: media_player.media_pause

Hier die script.yaml für die Radiosender:

'1589712176242':
  alias: Sonos N-JOY
  sequence:
  - data:
      media_content_id: x-rincon-mp3radio://https://ndr-edge-20b2-fra-lg-cdn.cast.addradio.de/ndr/njoy/live/mp3/128/stream.mp3?ar-distributor=f0a0
      media_content_type: music
    entity_id: media_player.arbeitszimmer
    service: media_player.play_media
'1589712176243':
  alias: Sonos NDR1
  sequence:
  - data:
      media_content_id: x-rincon-mp3radio://http://ndr-edge-2040.fra-lg.cdn.addradio.net/ndr/ndr1niedersachsen/osnabrueck/mp3/128/stream.mp3?ar-distributor=f0a1
      media_content_type: music
    entity_id: media_player.arbeitszimmer
    service: media_player.play_media
'1589712176244':
  alias: Sonos NDR2
  sequence:
  - data:
      media_content_id: x-rincon-mp3radio://https://ndr-edge-2042-dus-lg-cdn.cast.addradio.de/ndr/ndr2/niedersachsen/mp3/128/stream.mp3?ar-distributor=f0a0
      media_content_type: music
    entity_id: media_player.arbeitszimmer
    service: media_player.play_media
'1589712176245':
  alias: Sonos WDR2
  sequence:
  - data:
      media_content_id: x-rincon-mp3radio://http://wdr-edge-20be.fra-lg.cdn.addradio.net/wdr/wdr2/ostwestfalenlippe/mp3/128/stream.mp3?ar-distributor=f0a1
      media_content_type: music
    entity_id: media_player.arbeitszimmer
    service: media_player.play_media
'1589712176246':
  alias: Sonos klassik radio
  sequence:
  - data:
      media_content_id: aac://http://klassikr.streamabc.net/klassikradio-simulcast-aac-mq?sABC=5rp13r37%230%23sn4509n52q331926po81q2s45849spp0%23GharVa&amp;amsparams=playerid:TuneIn;skey:1589722679
      media_content_type: music
    entity_id: media_player.arbeitszimmer
    service: media_player.play_media
'1589712176247':
  alias: Sonos radio herford
  sequence:
  - data:
      media_content_id: x-rincon-mp3radio://http://radioherford-ais-edge-4004-212-122-133-229.cast.addradio.de/radioherford/live/mp3/high?ar-distributor=f0a1
      media_content_type: music
    entity_id: media_player.arbeitszimmer
    service: media_player.play_media

Eine Vorlage für die Logos auf dem Würfel findest Du hier (*.pdf Datei).

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.