So I’m new to home assistant, started a couple of days ago, with no prior coding knowledge. The main reason for me to start with hass, is the ability to send http commands to my soundbar for direct input switching. To clarify, the soundbar (HW-Q90R) doesn’t support this method of input switching, only cycling with one button, logitech messes up most of the time.
I got the the activities working, including status updater so i can change and view the harmony activities from the frontend. I also made some scripts with the commands I want to send to my soundbar.
But now I want to include this in the automation script, so when the activity updater changes to e.g. ps4 it will fire the appropriate script so the http command will change the input.
I tried alot of different approaches, but none seem to fire the script when selecting an activity. I also checked the logs for this. Any help would be greatly appreciated!
Configuration.yaml
#info
remote:
- platform: harmony
name: Harmony
host: 192.168.2.3
#select activity
input_select:
harmony:
name: Harmony
options:
- Select Input
- Kpn
- PS4
- Films en series
- SmartHub
- Nintendo Switch
- Netflix
- Amazon
- PowerOff
initial: Select Input
#HDMI switcher
rest_command:
hdmi2:
url: 'http://192.168.2.13:56001/UIC?cmd=%3Cname%3ESetFunc%3C/name%3E%3Cp%20type=%22str%22%20name=%22function%22%20val=%22hdmi2%22/%3E'
hdmi1:
url: 'http://192.168.2.13:56001/UIC?cmd=%3Cname%3ESetFunc%3C/name%3E%3Cp%20type=%22str%22%20name=%22function%22%20val=%22hdmi1%22/%3E'
arc:
url: 'http://192.168.2.13:56001/UIC?cmd=%3Cname%3ESetFunc%3C/name%3E%3Cp%20type=%22str%22%20name=%22function%22%20val=%22arc%22/%3E'
#current activity
sensor:
- platform: template
sensors:
harmony:
value_template: '{{ state_attr("remote.harmony", "current_activity") }}'
Automations.yaml
#harmony activity automation
- alias: Harmony activity switcher
hide_entity: True
trigger:
platform: state
entity_id: input_select.harmony
action:
service: remote.turn_on
entity_id: remote.harmony
data_template:
activity: >
{% if is_state("input_select.harmony", "Kpn") %}
38064190
{% elif is_state("input_select.harmony", "PS4") %}
38064389
{% elif is_state("input_select.harmony", "Films en series") %}
38064453
{% elif is_state("input_select.harmony", "SmartHub") %}
41690741
{% elif is_state("input_select.harmony", "Nintendo Switch") %}
44273777
{% elif is_state("input_select.harmony", "Netflix") %}
45009580
{% elif is_state("input_select.harmony", "Amazon") %}
45009590
{% else %}
-1
{% endif %}
#activity update
- alias: Harmony activity updater
hide_entity: True
trigger:
platform: state
entity_id: remote.harmony
action:
service: input_select.select_option
data_template:
entity_id: input_select.harmony
option: "{{ states.remote.harmony.attributes.current_activity }}"
Scripts.yaml
#PS4 - HDMI 2
ps4:
alias: hdmi2script
description: 'Switch to correct HDMI'
sequence:
- alias: ps4
service: rest_command.hdmi2
#Dune - HDMI 1
dune:
alias: hdmi1script
description: 'Switch to correct HDMI'
sequence:
- alias: dune
service: rest_command.hdmi1
#Kpn - ARC
kpn:
alias: arcscript
description: 'Switch to correct HDMI'
sequence:
- alias: kpn
service: rest_command.arc
#Smarthub - ARC
smarthub:
alias: arcscript
description: 'Switch to correct HDMI'
sequence:
- alias: kpn
service: rest_command.arc
#switch - ARC
switch:
alias: arcscript
description: 'Switch to correct HDMI'
sequence:
- alias: kpn
service: rest_command.arc
#netflix - ARC
netflix:
alias: arcscript
description: 'Switch to correct HDMI'
sequence:
- alias: kpn
service: rest_command.arc
#amazon - ARC
amazon:
alias: arcscript
description: 'Switch to correct HDMI'
sequence:
- alias: kpn
service: rest_command.arc