Hi,
every day I dig deeper into Hass.
After a lot of research I still cant get through how I manage my macros.
I read the instructions for “group”, “template switches” and “Command Line Switch” but I guess Im searching on the wrong place
What I try to do is relatively intuitive.
I need a switch to toggle a scene:
Mediacenter ON:
Your action:part will not work, bad sintaxis.
For every component you want to switch, it needs to be a service: call.
Take a look here (the automation 2 part).
Also take a look at the cookbook to get more examples
As a starter you can omit the automation entirely (and add it to your automation later on)
For both your scenarios (media center on / media center off)
create a script (below only one):
script:
media_center_on:
alias: Turn media center on.
sequence:
- service: media_player.turn_on
entity_id: media_player.avr_denon
- service: switch.turn_on
entity_id:
- switch.tv
- switch.wol_htpc
If you didn’t define any “default_view” as a group your script should come up in you ui automatically with an “activate” button.
Please let me know if that works for you…
Errors are: 17-01-24 12:03:32 homeassistant.bootstrap: Invalid config for [switch]: string value is None for dictionary value @ data['platform']. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 174). Please check the docs at https://home-assistant.io/components/switch/ 17-01-24 12:04:11 homeassistant.bootstrap: Invalid config for [automation]: Entity ID switch_mediacenter is an invalid entity id for dictionary value @ data['trigger'][0]['entity_id']. Got None Service media_player.select_source.htpc does not match format <domain>.<name> for dictionary value @ data['action'][2]['service']. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 87). Please check the docs at https://home-assistant.io/components/automation/ 17-01-24 12:04:11 homeassistant.bootstrap: Invalid config for [automation]: Entity ID switch_mediacenter is an invalid entity id for dictionary value @ data['trigger'][0]['entity_id']. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 87). Please check the docs at https://home-assistant.io/components/automation/ 17-01-24 12:04:11 homeassistant.bootstrap: component automation failed to initialize
What I coundt find till now is: I havent implemented a switch yet so entity_id: switch_mediacenter will be created automatically or do I have to implement that switch separately?
If so, it would be an empty switch. Dont know exactly how to do that…
@sanders:
Yeah, I thought I get a switch that would “switch” multiple components when I activate it. And later on I could link that switch to an automation.
Will try your sollution as well.
There are so many possibilities that I dont know which I should take.
But I guess the simplest for the moment with the opportunity to take it to more complexity as for Alexa or automation.
@5p4rtan
The switch “switch_mediacenter” is not created automatically.
You need to define it first.
If I were to solve this I’d try to make the problem smaller and focus on the action part by creating a separate script like I described. If that works, you don’t have to look at it again and focus on other parts of what you’re trying to do.
@sanders:
Yes thanks, I will try that once Im home again
Cause I cant test it right now may I ask,
will the script have just an on button (no switch) or could I also define an off state?
For Alexa I need to have an on/off switch in order to turn the script properly on and of with only one command.
@5p4rtan
Well, conceptually a script or an automation cannot be “on” or “off”. It can only run/start.
When your talking on or off, what would be the state of your media_center when one of the devices in that automation (like media_player.avr_wohnzimmer) is switched off manually ?
So my suggestion would be to have two scripts: media_center_on and media_center_off
In future I plan to extend these sort of scripts (I will have an aditional for TV, XBox, FireTV…) wiht if/else cases. If allready on just switch source etc.
Therefore I would also check the corresponding device state.
But for now it wouldnt make a difference if a device is allready of, cause there is no state toggle (if off then on)
Another problem is as I mentioned before. If I have to separate scripts, the Emulated Hue Bridge simulates two scripts as well. To avoid entity collision I have to use different names like:
script: “mediacenter_on” and script: “mediacenter_off”.
Alexa would get two emulated devices (mediacenter__on and mediacenter__off) and I would have to say: “Alexa, mediacenter onon” or “Alexa, mediacenteroff off” instead of just “Alexa, mediacenter on” or off.
Furthermore there would also be two script pattern instead of one switch.
I like these style of two separate script files but therefore it would be nice if I coud hide them and link their activation to a dummy switch.
But for that I have no cloue how to create souch an empty switch…
EDIT : I tried to use a commandline switch but with no success till now:
You can with the emulated_hue component. Just expose the input_boolean domain, give it an emulated_hue_name, and then rescan for devices (via voice or app).
If you put the code below in your configuration.yaml there will be a toggle button in your frontend. If you are able to control that through alexa then there are only a few steps left to get what you want. But you need to try -and confirm- that first.
input_boolean:
play_media:
name: media player on or off
initial: off
input_boolean:
play_media:
name: media player on or off
initial: off
automation:
- alias: switch on media player.
trigger:
platform: state
entity_id: input_boolean.play_media
from: 'off'
to: 'on'
action:
service: script.turn_on
entity_id: script.mediacenter_on
- alias: switch off media player.
trigger:
platform: state
entity_id: input_boolean.play_media
from: 'on'
to: 'off'
action:
service: script.turn_on
entity_id: script.mediacenter_off