txbdan
July 6, 2022, 1:05am
41
Hi all,
Beginner here. I’d like to create an Automation to trigger a Hue dynamic scene using the Philips Hue automation. I have a dynamic scene visible in the HA dashboard and I can call in in an automation, but I see no options or settings for setting dynamic to true. Where is the above GUI? I can’t find that.
see post: Select/activate Hue scenes in new v2 Api setup - #27 by Mariusthvdb
Though recent changes were implemented and changed to:
type: entities
title: Set Hue scenes
show_header_toggle: false
card_mod:
class: class-header-margin
entities:
- input_select.hue_group
- type: custom:fold-entity-row
card_mod: &scroll
style: |
#measure {
max-height: 300px;
overflow-x: hidden;
overflow-y: scroll;
}
head:
type: section
label: Regular scenes
card_mod: &label
style: |
.label {
margin-left: 0px;
}
padding: 0
entities:
- type: custom:auto-entities
card: &mod
type: entities
card_mod:
style: |
ha-card {
box-shadow: none;
margin: 0px -16px;
}
show_empty: false
filter:
template: |
{% set hue_group = states('input_select.hue_group') %}
{% set ns = namespace(scenes=[]) %}
{%- for s in states.scene
if hue_group == s.attributes.group_name and
s.attributes.is_dynamic != true %}
{% set ns.scenes = ns.scenes + [{'entity':s.entity_id,
'name': s.object_id.split(hue_group|slugify +'_')[1]|capitalize|replace('_',' ') }] %}
{%- endfor %}
{{ns.scenes}}
- type: conditional
conditions:
- entity: binary_sensor.selected_hue_group_has_active_scenes_available
state: 'on'
row:
type: custom:fold-entity-row
#card_mod: *scroll
head:
type: section
label: Dynamic scenes
card_mod: *label
padding: 0
entities:
- type: custom:auto-entities
card:
type: entities
card_mod:
style: |
ha-card {
box-shadow: none;
margin: 0px -16px;
}
.card-content {
max-height: 250px;
overflow-y: scroll;
}
filter:
# list with scenes, without the group name, to have better frontend presentation
template: |
{% set hue_group = states('input_select.hue_group') %}
{% set ns = namespace(scenes=[]) %}
{%- for s in states.scene
if hue_group == s.attributes.group_name and
s.attributes.is_dynamic == true %}
{% set ns.scenes = ns.scenes + [{'entity':s.entity_id,
'name': s.object_id.split(hue_group|slugify +'_')[1]|capitalize|replace('_',' ') }] %}
{%- endfor %}
{{ns.scenes}}
# list with scenes and their full name, including the group name
# {% set hue_group = states('input_select.hue_group') %}
# {% set ns = namespace(scenes=[]) %}
# {%- for s in states.scene
# if hue_group == s.attributes.group_name and
# s.attributes.is_dynamic == true %}
# {% set ns.scenes = ns.scenes + [s.entity_id] %}
# {%- endfor %}
# {{ns.scenes}}
- input_select.hue_dynamic_scene
- input_number.hue_dynamic_scene_speed
- input_number.hue_dynamic_scene_brightness
- type: conditional
conditions:
- entity: binary_sensor.selected_hue_group_active_scene
state: 'off'
row:
entity: script.activate_hue_dynamic_scene
icon: mdi:play
action_name: play
- type: conditional
conditions:
- entity: binary_sensor.selected_hue_group_active_scene
state: 'on'
row:
entity: script.deactivate_hue_dynamic_scene
icon: mdi:stop
action_name: stop
- type: conditional
conditions:
- entity: binary_sensor.hue_groups_dynamic_scening
state: 'on'
row:
type: custom:fold-entity-row
head:
type: section
label: Currently scening group
card_mod: *label
padding: 0
entities:
- type: custom:auto-entities
card: *mod
show_empty: false
filter:
include:
- attributes:
dynamics: true
# {{states.light
# |selectattr('attributes.dynamics','eq',true)
# |map(attribute='name')|list}}
- type: conditional
conditions:
- entity: binary_sensor.hue_groups_dynamic_scening
state: 'on'
row:
type: custom:fold-entity-row
head:
type: section
label: Currently scening lights
card_mod: *label
padding: 0
entities:
- type: custom:auto-entities
card: *mod
show_empty: false
filter:
include:
- attributes:
dynamics: dynamic_palette
- type: custom:template-entity-row
entity: >
light.{{states('input_select.hue_group')|slugify}}
secondary: >
{% set x = ['unknown','unavailable'] %}
{% if states('input_select.hue_group') not in x %}
{% set object = states('input_select.hue_group')|slugify %}
{% set group = 'light.' + object %}
{% set bri = state_attr(group,'brightness') %}
{% set rgb = state_attr(group,'rgb_color') %}
{% if states(group) == 'on' %} Bri: {{bri}}, Rgb: {{rgb}}
{% else %} Off
{% endif %} since {{relative_time(states[group].last_changed) if (states[group]
and states[group].last_changed not in x) else 'Initializing....'}}
{% else %} Not yet set
{% endif %}
toggle: true
- type: custom:fold-entity-row
head:
type: section
label: Automations
card_mod: *label
group_config:
secondary_info: last-triggered
state_color: true
padding: 0
entities:
- automation.auto_populate_hue_group_input_select
- automation.auto_populate_hue_dynamic_scene_input_select
so people dot have to scroll up, these 2 automations populate the input_selects:
automation:
- alias: Auto populate Hue group input select
id: auto_populate_hue_group_input_select
mode: restart
trigger:
platform: event
event_type: delayed_homeassistant_start
action:
service: input_select.set_options
target:
entity_id: input_select.hue_group
data:
options: >
{{expand(integration_entities('Philips Hue 1'))
|selectattr('attributes.is_hue_group','defined')
|selectattr('attributes.is_hue_group','eq',true)
|map(attribute='name')|list}}
- alias: Auto populate Hue dynamic scene input select
id: auto_populate_hue_dynamic_scene_input_select
mode: restart
trigger:
platform: state
entity_id: input_select.hue_group
action:
service: input_select.set_options
target:
entity_id: input_select.hue_dynamic_scene
data:
options: >
{% set hue_group = states('input_select.hue_group') %}
{{states.scene
|selectattr('attributes.group_name','defined')
|selectattr('attributes.group_name','eq',hue_group)
|selectattr('attributes.is_dynamic','eq',true)
|map(attribute='name')|list}}
The input_selects need to ‘exist’ so you have to create them in eg helpers, and set 1 option. Those will be overwritten.
3 Likes
Mikypan81
(Michele)
November 16, 2022, 5:31pm
43
Mariusthvdb:
automation:
- alias: Auto populate Hue group input select
id: auto_populate_hue_group_input_select
mode: restart
trigger:
platform: event
event_type: delayed_homeassistant_start
action:
service: input_select.set_options
target:
entity_id: input_select.hue_group
data:
options: >
{{expand(integration_entities('Philips Hue 1'))
|selectattr('attributes.is_hue_group','defined')
|selectattr('attributes.is_hue_group','eq',true)
|map(attribute='name')|list}}
- alias: Auto populate Hue dynamic scene input select
id: auto_populate_hue_dynamic_scene_input_select
mode: restart
trigger:
platform: state
entity_id: input_select.hue_group
action:
service: input_select.set_options
target:
entity_id: input_select.hue_dynamic_scene
data:
options: >
{% set hue_group = states('input_select.hue_group') %}
{{states.scene
|selectattr('attributes.group_name','defined')
|selectattr('attributes.group_name','eq',hue_group)
|selectattr('attributes.is_dynamic','eq',true)
|map(attribute='name')|list}}
Hello, I’m a noob, can you help me?
I can’t figure out where to put this code. I put it in automation.yaml but it gave me error
In log viewer I see this error
2022-11-16 18:44:16.747 ERROR (MainThread) [homeassistant.components.automation.auto_populate_hue_group_input_select] Auto populate Hue group input select: Error executing script. Invalid data for call_service at pos 1: length of value must be at least 1 for dictionary value @ data['options']
2022-11-16 18:44:16.755 ERROR (MainThread) [homeassistant.components.automation.auto_populate_hue_group_input_select] Error while executing automation automation.auto_populate_hue_group_input_select: length of value must be at least 1 for dictionary value @ data['options']
well, it has to be anywhere under that automation:
top-level yes.
also, in my automation, I reference certain entities. You should ofc adapt the entity_id’s to what you have in your setup. Other than that, I cant say much really.
Did you try with a single automation? always start small and let it grow from a valid config…
123
(Taras)
November 16, 2022, 6:47pm
45
Changing 'Philips Hue 1'
to 'Philips hue'
is what fixed it for me. It’s case-sensitive so 'Philips Hue'
didn’t work.
Don’t forget to change input_select.hue_group
to the entity_id of your input_select.
ah yes, that could be it. I have 3 Hue hubs, and named them accordingly. I want only Hub 1 iterated, so naming that does work.
Thats what I meant with adapt the entity_id’s. Should have mentioned this explicitly. sorry for that.
Mikypan81
(Michele)
November 16, 2022, 11:39pm
47
Mariusthvdb:
{{expand(integration_entities('Philips Hue 1'))
|selectattr('attributes.is_hue_group','defined')
|selectattr('attributes.is_hue_group','eq',true)
|map(attribute='name')|list}}
Thank you for reply me, but don’t understand how bypass that error.
I post a screen of my error if I try to use automation system of home assistant
123
(Taras)
November 17, 2022, 1:45am
48
You didn’t copy Mariusthvdb’s example correctly. Your version doesn’t have correct indentation. The first line of the template should be indented by an additional three spaces.
what Taras said.
are you sure your template works in the dev template page, on /developer-tools/template or Link to Developer Tools: Templates – My Home Assistant ? you should always check that, to rule out simple template issues.
Mikypan81
(Michele)
November 17, 2022, 9:15am
50
Mariusthvdb:
{{expand(integration_entities('Philips Hue 1'))
|selectattr('attributes.is_hue_group','defined')
|selectattr('attributes.is_hue_group','eq',true)
|map(attribute='name')|list}}
I’ve tested the model on developer tools and it reach the correct groups from my hue.
but when try to insert in “create automation”, get the error.
I’ve tried to give three spaces additional to first line, but still get same error.
Message malformed: expected dict for dictionary value @ data['event_data']
as far as I can see I your screenshot you have:
data:
options: >
{{expand
and at least that should be:
data:
options: >
{{expand
in a good code editor, you should see those lines get a color (or not) depending on the correct syntax
1 Like
Mikypan81
(Michele)
November 17, 2022, 3:28pm
52
Thank you so much @Mariusthvdb , it works.
Now I’ve to integrate all you mentioned in above posts
##########################################################################################
# Inputs
##########################################################################################
input_select:
# need at least 1 option for the config check, which will be overwritten during startup
hue_group:
name: Select Hue group
options:
- Alarm
# initial: Alarm
hue_dynamic_scene:
name: Hue Dynamic scene
options:
- 'Alarm - Tyrell'
input_number:
hue_dynamic_scene_speed:
name: Hue scene speed
min: 0
max: 100
step: 10
hue_dynamic_scene_brightness:
name: Hue scene brightness
min: 0
max: 255
step: 10
##########################################################################################
# Templates
##########################################################################################
template:
binary_sensor:
- unique_id: selected_hue_group_active_scene
name: Selected Hue group active scene
state: >
{% set select = states('input_select.hue_group')|slugify %}
{% set group ='light.' + select %}
{{is_state_attr(group,'dynamics',true)}}
- unique_id: selected_hue_group_has_active_scenes_available
name: Selected Hue group has active scenes available
state: >
{% set hue_group = states('input_select.hue_group') %}
{{states.scene
|selectattr('attributes.group_name','eq',hue_group)
|selectattr('attributes.is_dynamic','eq',true)|list|length != 0}}
- unique_id: hue_groups_dynamic_scening
name: Hue groups dynamic scening
state: >
{{states.light|selectattr('attributes.dynamics','eq',true)|list|length != 0}}
# {% set select = states('input_select.hue_group') %}
# {% set group = states.light
# |selectattr('attributes.friendly_name','eq',select)
# |map(attribute='entity_id')|join %}
# {{is_state_attr(group,'dynamics',true)}}
##########################################################################################
# Scripts
##########################################################################################
script:
activate_hue_dynamic_scene:
alias: Activate Hue dynamic scene
mode: restart
icon: mdi:power
sequence:
- condition: >
{{is_state('binary_sensor.selected_hue_group_active_scene','off')}}
# first record current state of lights in the selected group
- service: scene.create
data:
scene_id: before_dynamic_scene
snapshot_entities:
- >
{% set select = states('input_select.hue_group')|slugify %}
{% set group ='light.' + select %}
{{group}}
- service: hue.activate_scene
data:
dynamic: true
speed: >
{{states('input_number.hue_dynamic_scene_speed')|int}}
brightness: >
{{states('input_number.hue_dynamic_scene_brightness')|int}}
target:
entity_id: >
{% set select = states('input_select.hue_dynamic_scene')|slugify %}
{{'scene.' + select}}
# {% set select = states('input_select.hue_dynamic_scene')%}
# {{states.scene
# |selectattr('attributes.friendly_name','eq',select)
# |map(attribute='entity_id')|join}}
deactivate_hue_dynamic_scene:
alias: Deactivate Hue dynamic scene
mode: restart
icon: mdi:power-off
sequence:
- condition: >
{{is_state('binary_sensor.selected_hue_group_active_scene','on')}}
- service: hue.activate_scene
data:
dynamic: false
target:
entity_id: >
{% set select = states('input_select.hue_dynamic_scene')|slugify %}
{{'scene.' + select}}
# reset the lights to the state before the dynamic scene activation
- service: scene.turn_on
target:
entity_id: scene.before_dynamic_scene
# - service: light.turn_on
# data:
# profile: relax
# target:
# entity_id: >
# {{'light.' + states('input_select.hue_group')|slugify}}
# {% set select = states('input_select.hue_dynamic_scene')%}
# {{states.scene
# |selectattr('attributes.friendly_name','eq',select)
# |map(attribute='entity_id')|join}}
##########################################################################################
# Automations
##########################################################################################
automation:
- alias: Auto populate Hue group input select
id: Auto populate Hue group input select
mode: restart
trigger:
platform: event
event_type: delayed_homeassistant_start
action:
service: input_select.set_options
target:
entity_id: input_select.hue_group
data:
options: >
# expand(integration_entities('Philips Hue 1'))
{{states.light
|selectattr('attributes.is_hue_group','eq',true)
|map(attribute='name')|list}}
- alias: Auto populate Hue dynamic scene input select
id: Auto populate Hue dynamic scene input select
mode: restart
trigger:
- platform: event
event_type: delayed_homeassistant_start
- platform: state
entity_id: input_select.hue_group
action:
service: input_select.set_options
target:
entity_id: input_select.hue_dynamic_scene
data:
options: >
{% set hue_group = states('input_select.hue_group') %}
{{states.scene
|selectattr('attributes.group_name','eq',hue_group)
|selectattr('attributes.is_dynamic','eq',true)
|map(attribute='name')|list}}
So, it’s
Input
Templates
Scripts
Automation (OK)
I don’t know where paste Templates, can you help me?
probably because you didnt add it under templates:
?
if you enable packages in your config, all you need to do is add the full yaml above in a package, and you’re set.
If you dont use packages, you need to add those entries for all top level domains under the existing ones in your current configuration.yaml
1 Like
Mikypan81
(Michele)
November 24, 2022, 12:04am
55
Hello there.
I’m at the end of my page.
Now I’m able to view my groups, select my static or dynamis scenes, activate and play.
Just two question:
how I can add photos on the circle on the left of my scenes’s name??? I’ve tryied with no success
In dynamic scenes, after clicked on “play”, if I change speed, I’ve no reaction, but if I stop, change speed and then re play, I can see my speed’s change. It’s normal?? Or is it supposed to change instantly?
Thank you
see: Select/activate Hue scenes in new v2 Api setup - #11 by Mariusthvdb
tbh, I dont know, I dont use this very often… it might be a HUE Api thing, why happens when you do that in the app?
just tested it, and I can see that too, it simply is the wait is probably… maybe you can write an automation triggering on the slider
Fidelity
(Maurice)
July 19, 2023, 3:16pm
57
How could I use these scenes with a Philips Hue but WITHOUT a bridge? I can control the lights with Bluetooth with the Hue app and set scenes. But I’m looking for a way to set scenes using Home Assistant using Zigbee. I was hoping this was the way to go, but this seems to rely on a Philips Hue bridge being present
Well yes that’s life: if you don’t use a hue bridge you can’t use hue bridge functionality…
Fidelity
(Maurice)
August 14, 2023, 7:44am
59
It’s not really a Hue bridge functionality now is it…? If I set a scene “fireworks” in Hue Bridge, the lights turn yellow, blue, white, yellow and don’t change (no effects). That’s something I can already manually do in Home Assistant. Why would I buy a silly Hue Bridge for that?
There must be a way to simply click a button to mimick the scenes from the Hue Bridge. Or maybe even use community made scenes.
Sure, you can do that. Just find out what Hue does exactly and written that up yourself.
Silly me.
Is there a way to have this installed via HACS? Thanks