Entities Card - Setting Hue Scene

Hi folks,

I’m just getting into editing the lovelace ui, and I don’t know the best way to control my hue lights the way I want.

I would like a card that has my lights listed, with an on/off slider to the right. When the light is turned on, it should go to a specific hue scene.

the below code (somewhat) works in the glance card, but I prefer the on/off slider.

However, when I use the code on the entities card, it toggles the light on/off, but does not fire off the scene.

any comments on how I fix my code?

thanks

type: entities
entities:
  - entity: light.hall
    name: Hall
    tap_action:
      action: call-service
      service: hue.hue_activate_scene
      service_data:
        group_name: Living Room
        scene_name: Bright
  - entity: light.other

an entity row cannot call a service. You need to use a service row.

type: entities
entities:
  - type: call-service
    action_name: Hall 
    service: hue.hue_activate_scene
    service_data:
      group_name: Living Room
      scene_name: Bright
  - entity: light.other

Just an FYI you can’t mix and match any old configuration. Seems like you just pieced a bunch of things together that you thought would work without consulting the docs.

The docs themselves do a pretty good job at letting you know what’s available for configuration.

For example in the entities card, the available configuration fields are defined in configuration variables section of the docs.

meaning, at the top level, the only valid attributes for an entities card is:

type: entities
entities:
title:
show_header_toggle:
theme:

Any field outside of that is not valid. Now the next section of those docs is called ‘Options for Entities’. This covers all items that can be placed into the entities field.

You’ll notice in that section, the only available attributes are:

 - entity: 
   type:
   name:
   icon:
   secondary_info:
   format:

Notice how tap_action is not an option. Now take a look at your configuration.

type: entities
entities:
  - entity: light.hall
    name: Hall
    tap_action: #<------------------ USING TAP ACTION AS A FIELD.
      action: call-service
      service: hue.hue_activate_scene
      service_data:
        group_name: Living Room
        scene_name: Bright
  - entity: light.other

Ultimately the reason your configuration isn’t working is because lovelace is completely ignoring your extra fields and only using the ones that it cares about. Which is essentially this:

type: entities
entities:
  - entity: light.hall
    name: Hall
  - entity: light.other

The last section is called Special Row Elements. This section contains anything else that you can place into the entities row. This is where the docs are alittle lacking. They don’t really mention that these rows go in the entities section. Either way, they do.

So with that being said, the special row that you should use (that I stated above) is the call service element.

Thanks, I got it sorted out, however, it still doesn’t give me the UI I’m looking for.

Is there another method/card that will just show the on/off slider, and can call a scene?

I have my lights change brightness, and colors throughout the day, so ‘just turning it on’ brings up that last color/brightness settings, which isn’t what I want.

You can make a template light and display that with the custom slider card.

light:
  - platform: template
    lights:
      hall_hue_scene:
        value_template: "{{ states('light.hall') }}"
        level_template: "{{ state_attr('light.hall','brightness') }}"
        turn_on:
          service: hue.hue_activate_scene
          data:
            group_name: Living Room
            scene_name: Bright
        turn_off:
          service: hue.hue_activate_scene
          data:
            group_name: Living Room
            scene_name: Off #<--- CHANGE TO WHATEVER YOUR OFF IS
        set_level:
          service: light.turn_on
          data_template:
            entity_id: light.hall
            brightness: "{{ brightness }}"

Then display that in lovelace using lovelace-slider-entity-row

type: entities
entities:
  - type: custom:slider-entity-row
    entity: light.hall_hue_scene
    toggle: true

It’ll look something like this

thanks so much for your help so far…

I wasn’t sure how to do an ‘off’ scene with hue, as it said I had to have one light on.

so, I’m trying a different service, but when I turn off the slider, it slides off, then slides back on again.

  - platform: template
    lights:
      hall_hue_scene:
        value_template: "{{ states('light.hall') }}"
        level_template: "{{ state_attr('light.hall','brightness') }}"
        turn_on:
          service: hue.hue_activate_scene
          data:
            group_name: Living Room
            scene_name: Bright
        turn_off:
          service: light.turn_off
          data_template:
            entity_id: light.hall
        set_level:
          service: light.turn_on
          data_template:
            entity_id: light.hall
            brightness: "{{ brightness }}"

Does the light adjust it’s brightness?

Yes, the slider will adjust the brightness of the light.

the on/off switch will turn the light off, but then the switch goes back to the on position, but the light stays off.

That’s because the light is still on. Moving the brightness all the way down doesn’t turn the light off, it just turns the brightness off or puts it into low voltage. If you look at the light light.hall, you’ll probably notice that it’s still on when you turn the brightness all the way down.

If you want to ignore that behavior, you can adjust your value_template to reflect that

        value_template: "{{ state_attr('light.hall', 'brightness') | int > 0 }}"

just as a fyi, a ‘fix’ has just been made so the sliders can’t turn-off the lights any longer. I use the quotes because im my experience this is an unfortunate decision. It was made however…

I use a setup for my Hue scenes, and created an extra ‘off’ scene so I can use that in the same card:

38

id be glad to share it you want, though it might probably be on the community elsewhere for some time :wink:
found it: Hue scenes mimicked in Ha (and on Buttons, was Tiles) though I changed my current code somewhat, this will give you an idea.

1 Like

I’m not using the slider to try and turn off the light, I was just mentioning that it does have an affect on the light.

I am expecting/hoping that the on/off switch does turn it off.

I modified the value template as you described, and I’m still having the issue, but it appears it may be ‘picnic’.

Below is a screenshot of the slider card, and just the entities card.

Currently, the ‘Hall’ is off, and it truly is off. If I push the 'hall_hue_scene on/off button, it slides the on/off to the left, turns grey. 1 second later, it slides to the right, turning blue.

I assume I am turning off the ‘hall’ in the code, but I’m not turning off ‘hall_hue_scene’??

2019-09-19_093951

  - platform: template
    lights:
      hall_hue_scene:
        #value_template: "{{ states('light.hall') }}"
        value_template: "{{ state_attr('light.hall', 'brightness') | int > 0 }}"
        level_template: "{{ state_attr('light.hall','brightness') }}"
        turn_on:
          service: hue.hue_activate_scene
          data:
            group_name: Living Room
            scene_name: Bright
        turn_off:
          service: light.turn_off
          data_template:
            entity_id: light.hall
        set_level:
          service: light.turn_on
          data_template:
            entity_id: light.hall
            brightness: "{{ brightness }}"            
            

There is definitely some confusion here because you said:

So lets back up and clarify a few things. First, move back to the original value_template. That’s what you want.

Second, Clarify these questions with Yes/No responses, because your lingo isn’t matching up with what I’m thinking.

When using this template:

  - platform: template
    lights:
      hall_hue_scene:
        value_template: "{{ states('light.hall') }}"
        level_template: "{{ state_attr('light.hall','brightness') }}"
        turn_on:
          service: hue.hue_activate_scene
          data:
            group_name: Living Room
            scene_name: Bright
        turn_off:
          service: light.turn_off
          data_template:
            entity_id: light.hall
        set_level:
          service: light.turn_on
          data_template:
            entity_id: light.hall
            brightness: "{{ brightness }}"
  1. Does the slider adjust the brightness of the light?
  2. When off, does the toggle turn the physical light on?
  3. When on, does the toggle turn the physical light off?

If the answer is yes to everything, then the light is working as expected.

Lastly, I believe you may be noticing a delay for the toggle. It may flip/flop during a transition period when you change the state of these devices. If you have a long off → on or on → off transition period, the state of this light may not reflect the actual state for a few seconds.

This occurs because the light is still on when transitioning to off. Same goes for the opposite.

it might be a good idea to add the |int after the level_template, since when the light is Off the level_template would be None. Adding the |int makes that 0.

01

since you’re using hue lights, let me ask if the light.hall is a (hue) group or an indivual light. You’re mixing lights in the on/off services, and they’re in different rooms…is that on purpose?

Also, if your hall_hue_scene is on, what does the Hue app say?

  1. Yes
  2. Cannot test. I can’t toggle it off. When I toggle off, it toggles back on 1 second later. If the light was on when toggling off, it will turn off the light (confirmed thru hue app). the light does not turn back on when the toggles slides back
  3. Cannot test properly, due to above situation.

could it be you are using a data_template where there is no template…:

        turn_off:
          service: light.turn_off
          data_template:
            entity_id: light.hall

should probably be:

        turn_off:
          service: light.turn_off
          data:
            entity_id: light.hall

or as used when no extra data is provided:

        turn_off:
          service: light.turn_off
          entity_id: light.hall

and remember to use this:

level_template: "{{ state_attr('light.hall','brightness')|int }}"

The problem is that the light is not updating based off the state of the ‘light.hall’.

It doesn’t make sense why that is happening unless light.hall is not updating.

@phreaq Try this, maybe it’s not liking the state as 'on' / 'off'.

        value_template: "{{ is_state('light.hall','on') }}"

please let me ask, where does:

  data_template:
            entity_id: light.hall
            brightness: "{{ brightness }}"

get its value?
I’ve tried to rebuild this out of curiosity and learning experience but I can’t get this field to be populated with only the code in this post:

off:

on:

sorry if I miss the obvious…

hi folks, it seems Mariusthvdb’s tip worked, using the below code worked

        turn_off:
          service: light.turn_off
          entity_id: light.hall

Thanks for the help everyone!

It’s a template light, by default that field contains brightness which is passed when the lights slider is moved.

yes, I realize that, but never used template lights before. Seems all a bit confusing, when there is a level_template, and a brightness variable…

so this won’t work in the dev-template, before it is created as a true light template? Since I’ve been sliding left and right, and the variable didn’t show in the template editor, as you can see.

You can’t use the template editor to test it live. If you want to test, you need to make the variable yourself

{% set brightness = 4 %}