For latest version of package jump to Select/activate Hue scenes in new v2 Api setup - #27 by Mariusthvdb
---------------------
Anytime soon now we will see the light (…) of the new v2 Hue API @MarcelVeldt has been/is working miracles on, and I have been happy to test the last couple days.
Some amazing goodies are in store (for me personally the switches for the motion sensors that are now in core and no longer need complex rest/command_line sensors) and core active scenes for all our hue_groups. Also we will be able to differentiate between Hue groups and zones. all very cool stuff. Be sure to check it all out when it arrives!
Since I posted Hue scenes mimicked in Ha (and on Buttons, was Tiles) some very long time ago, and the set_hue_scene will also go, I decided to figure out a new way of doing all of that in the frontend. As much as possible in the frontend, with as little fiddling in the back-end as possible.
Think I made a config that is ready for sharing so here goes:
First, I create an input_select.hue_group_v2, in an automation at startup, which is auto-populated with the available scene for that specific selected group.
automation:
- alias: Auto populate Hue group v2 input select
id: Auto populate Hue group v2 input select
trigger:
platform: event
event_type: delayed_homeassistant_start # a specially made event, to first give HA some time
action:
service: input_select.set_options
target:
entity_id: input_select.hue_group_v2
data:
options: >
{{expand(device_entities(device_id('Philips Hue 1')))
|selectattr('attributes.is_hue_group','eq',true)
|map(attribute='name')|list}}
# {{expand(device_entities('yourbridgeidgoeshere'))
# |selectattr('attributes.is_hue_group','eq',true)
# |map(attribute='name')|list}}
input_select:
hue_group_v2:
name: Select Hue group
options:
- select
with that, the input_select is created, and can be used in the frontend:
type: entities
title: Set Inside Hue scenes
show_header_toggle: false
card_mod:
style: |
.card-header {
background-color: var(--background-color-off);
color: var(--text-color-off);
padding-top: 0px;
padding-bottom: 0px;
margin: 0px 0px 16px 0px;
}
entities:
- input_select.hue_group_v2
- type: custom:fold-entity-row
head:
type: section
label: Available Hue scenes
padding: 0
entities:
- type: custom:auto-entities
card:
type: entities
card_mod:
style: |
ha-card {
box-shadow: none;
margin: 0px -16px 0px -16px;
}
filter:
template: |
{% set select = states('input_select.hue_group_v2')|lower|replace(' ','_') %}
{%- for s in states.scene
if select == s.object_id.split('_')[:-1]|join('_') %}
{{s.entity_id}}
{%- endfor %}
# options:
# type: custom:template-entity-row
# name: >
# {{state_attr(config.entity,'name')}}
- type: custom:template-entity-row
entity: >
light.{{states('input_select.hue_group_v2')|lower|replace(' ','_')}}
secondary: >
{% set object = states('input_select.hue_group_v2')|lower|replace(' ','_')%}
{% 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)}}
toggle: true
# - type: divider
- entity: automation.auto_populate_hue_group_v2_input_select
secondary_info: last-triggered
result:
select group:
check available scenes and activate:
added a toggle to easily turn off gain:
Of course, none of this, and I can’t stress that enough, none of this, would have been possible without the amazing custom cards @ThomasLoven wrote, so next to Marcel, a huge thank you for Thomas is in order!
Hope this helps anyone looking for this functionality. Please see if you can build on this.
cheers.