Automation for Action on Sunrise

That’s already implemented.

You can change it in the automation action:


- service: script.auto_an_szenen ## or whatever your script is named now
  data:
    name: konzentrieren ## scene nick name == name of the scene in the Hue-App


You can also change the default settings directly in the script by changing the following passage:

More on this later.

I’ll try to break it down:



  szene: |-
  ## placeholder because we want to assign 2 values to each other:
  ## a certain Hue scene to a certain light
    {%- set x = namespace(szenen=[]) %}
  
  ## loop: does the assignment for us
    {%- for 
    
    #—> given variable for the result of the following code block
    hue

    #—> only evaluate domain light
    in states.light

    #—> only select existing hue groups == "Zimmer" in the Hue-App
    |selectattr('attributes.is_hue_group', 'defined')

    #—> only take lamps into account which are on
    |selectattr('state', 'eq', 'on')
    
    #—> pick up the object_id to use it later as variable 'hue'
    # == everything behind the first dot of an entity id
    # e.g. light.garden = entity_id, garden = object_id 
    |map(attribute='object_id')
    
    #—> ignore everything defined in the above variable "ignore"
    |reject('in', ignore)
    
    #—> display the result as a list
    |list %}
    
      {%- set x.szenen = 
      
      #—> put it all together to build the entity_id of the target scene
      # slugify ensures that the "normal" name of the Hue scene 
      # used in the variable "name" can be processed into its 
      # entity_id. 
      # Super very simply put, slugify converts a name into an entity_id
      x.szenen + ['scene.' ~ hue ~ '_' ~ name|slugify]
      |list %}

  ## end of loop
    {%- endfor %}
  ## result
    {{ x.szenen }}

No, because you wanted to control only those lamps which are already on.
I don’t think that you can use Hue scenes for a single light without before having it defined as zone, but I never tried.

1 Like