hugobloem / stateful_scenes

Stateful Scenes in Home Assistant (Home Kit scene compatible)
MIT License
47 stars 6 forks source link

Use scenes from Hue #35

Open barryvdh opened 9 months ago

barryvdh commented 9 months ago

I have a lot of scenes in Hue. Is it possible to get the scenes from there?

The scene does have brightness setting:

I think that roughly matches (if the temperature in lights is 0-255 instead of 0-100?)

image

What I do now is create a template that calls the scene, but shows the state from your scene.

type: grid
cards:
  - type: custom:mushroom-template-card
    entity: switch.helder_stateful_scene
    tap_action:
      action: call-service
      service: scene.turn_on
      target:
        entity_id:
          - scene.helder
        device_id: []
        area_id: []
    icon: hue:scene-bright
    primary: Helder
    multiline_secondary: true
    secondary: '{{  bool(states(entity)) | iif(''Aan'', ''Uit'')}}'
    icon_color: '{{ iif(bool(states(entity)), ''orange'', ''grey'') }}'

Which now calls the scene I created in HA, but that wouldn't be necessary in that case. But not sure how reliable it is.

(I used the call-service instead of the toggle because that seemed more reliable, to force the state even if already active)

mattmon commented 8 months ago

+1 The hue integration doesn’t fully sync scenes with HA, though does expose services to interact with them. Having the ability to determine which hue scene is active, per area, would be awesome.

hugobloem commented 8 months ago

I am happy to work on this but unfortunately, I don't have any Hue hardware. Does Hue provide any state information itself? Or any information as to what Lights are triggered by a scene?

barryvdh commented 8 months ago

I don't think so. I think it does map to a group, which can be used for the current value though.

hugobloem commented 8 months ago

Hmm, but there is no way of knowing what the values of the group are when the state is active...?

barryvdh commented 8 months ago

No, only by checking the brightness, similar to this automation.

What I currently do is is a helper, which is basically looping through all the states from Hue which have a certain Room as attribute, and match the first one in range. (There is a conversion bug in the Hue automation I think, hence the 100->255)

{%- for state in states
  | selectattr('domain', 'eq', 'scene')
  | selectattr('attributes.group_type', 'eq', 'room')
  | selectattr('attributes.group_name', 'eq', 'Living Room')
  | selectattr("attributes.brightness", 'defined')
  -%}
  {%if (state_attr('light.living_room', 'brightness') - state.attributes.brightness/100*255) | abs | int < 5 %}
    {{state.entity_id }}
    {% break %}
  {%endif %}
{%- endfor -%}
JoernBerkefeld commented 7 months ago

To add to that:

hugobloem commented 6 months ago

I am going to see whether it is possible to learn the scenes from Hue. That is, manually select what lights are in a scene, activate a scene, and then learn what state the lights are in when the scene is active. This will be more experimental, and I will see how far I get along.

Note that I don't have a Hue bridge so I will be testing this using virtual devices. If I get it working on that I might ask one of you to test it out using the Hue bridge.

hugobloem commented 5 months ago

I have created a first proof of concept to learn non-HA scenes. It is available in 1.3.0b0. Please try it out and report whether it is working or not.