Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95397

Use KNX switch to control media_player volume

$
0
0

@Wouter1 wrote:

I have been experimenting with controlling my media_player volume through a KNX switch. The approach I used was to use a dimming object in KNX. The volume adjustment catches the on/off switch events in Home Assistant, using automation to adjust the volume in steps. The long-press in KNX generates the dimming action in KNX, which I catch and use to trigger play/ pause automations.

Relevant parts from configuration.yaml:

knx:
  tunneling:
    ...
  fire_event: true
  fire_event_filter: ["3/5/*"]

automation:
  - alias: "Increase Volumer"
    trigger:
      platform: event
      event_type: knx_event
      event_data:
        address: '3/5/0'
        data: 1
    condition:
      condition: template
      value_template: "{{ (float(states('sensor.volume_achterkamer')) <= 0.9) }}"
    action:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.achterkamer
          volume_level: '{{ (float(states("sensor.volume_achterkamer")) + 0.1) | round(2) }}'
  - alias: "Decrease Volume"
    trigger:
      platform: event
      event_type: knx_event
      event_data:
        address: '3/5/0'
        data: 0
    condition:
      condition: template
      value_template: "{{ (float(states('sensor.volume_achterkamer')) > 0.1) }}"
    action:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.achterkamer
          volume_level: '{{ (float(states("sensor.volume_achterkamer")) - 0.1) | round(2) }}'
  - alias: "Media Play"
    trigger:
      platform: event
      event_type: knx_event
      event_data:
        address: '3/5/2'
        data: 9
    action:
      service: media_player.media_play
      entity_id: media_player.achterkamer
  - alias: "Media Pause"
    trigger:
      platform: event
      event_type: knx_event
      event_data:
        address: '3/5/2'
        data: 1
    action:
      service: media_player.media_pause
      entity_id: media_player.achterkamer

The result is that you need multiple presses of a button to lower the volume in discrete steps (in this case 10% of volume, but you can off-course take bigger or smaller steps), and can use the long-press for media play/pause. This works fine. In the ideal case however, I would like to have a long press continually lower/ increase the volume until the button is released. Short press can then be used for play/ pause. Is there anybody who got that working, or has any ideas for alternative approaches?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 95397

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>