I’m trying to make a complex routine (I feel anyway) but can I have some help in making it work, please?
I have a TV setup with 3 separate switches around the room with extension leads in with wireless speakers in them and it’s set to turn them all off if the TV isn’t being used after a set amount of time.
How do I turn off a group (“group.lounge_group”, which has: “Switch.TV”, “Switch.L” and “Switch.R”) unless “Switch.L” in that group is using over 6 watts, as a phone is being charged also for example, then only turn off “Switch.TV” and “Switch.R”?
For Starters, I’m not convinced {% else %} switch_r.turn_off switch_tv.turn_off {% endif %} is how to easily specify 2 devices to turn off in an ‘else’ clause, I guess how to specify those 2 devices is all I need, unless you tell me otherwise?
Below is my best guess based on what you have provided. If it doesn’t work, please post screen shots showing the entities in question in the Developer Tools > States tool.
According to what you have posted, the current consumption data is not available as an attribute of the switch entity. Does switch.sonos_play_1_l have an associated sensor that gives that data? If you click the the information button to the left of the entity name then click the “Related” tab of the pop-up it should be in the list.
Unfortunately it’s still turning the whole lot off
This is the entire block if you can see something else that may be affecting it. I’ve put the time to seconds so I can test it and to make sure HA is registering the current consumption as over 6 watts I turn on that plug separately before turning on the TV plug which should trigger this routine:
- id: '1673994034512'
alias: Lounge Plugs - Turn off if Idle
description: Turn off Lounge if Idle
trigger:
- platform: state
entity_id:
- switch.lounge_tv
from: 'off'
to: 'on'
id: tv plug goes on
for:
hours: 0
minutes: 0
seconds: 13
- platform: numeric_state
entity_id: sensor.lounge_tv_current_consumption
for:
hours: 0
minutes: 0
seconds: 12
below: 40
- platform: state
entity_id:
- sensor.lounge_tv_audio_input_format
for:
hours: 0
minutes: 0
seconds: 11
to: PCM 2.0 no audio
from: PCM 2.0
condition:
- condition: not
conditions:
- condition: state
entity_id: media_player.living_room_tv
state: playing
for:
hours: 0
minutes: 0
seconds: 0
action:
- service: homeassistant.turn_off
target:
entity_id: >
{% if states('sensor.sonos_play_1_l_current_consumption') | float(0) < 6 %}
{{ state_attr('group.lounge_group', 'entity_id') }}
{% else %} {{ ['switch.sonos_play_1_r', 'switch.lounge_tv'] }}
{% endif %}
target:
area_id: living_room
data: {}
mode: single
Fantastic Many thanks for your help on this, this behaving how I wanted now when it’s triggered I just need to work on why it is triggering unexpectedly now, but that is a different issue I have just discovered, so thanks again :).