Sorry for the basic question, but could I please get some help with the installation?
I’m just not sure what ...then add the configuration to enable the hacs module. means.
I’ve downloaded and copied the Python script into my custom_components folder and that’s pretty much as far as I got.
Brilliant, thanks.
I followed the instractions and got the following error:
2021-04-25 23:10:57 ERROR (MainThread) [homeassistant.components.automation.create_all_lights_group_on_startup] Create All Lights Group on Startup: Error executing script. Service not found for call_service at pos 1: Unable to find service python_scripts.create_all_group
2021-04-25 23:10:57 ERROR (MainThread) [homeassistant.components.automation.create_all_lights_group_on_startup] Error while executing automation automation.create_all_lights_group_on_startup: Unable to find service python_scripts.create_all_group
I’ve tried:
Changing the service tag to - service: config.python_scripts.create_all_group
Adding an __init__.py file to the python_scripts folder
On more thing with the light counting I have created few groups for (Ikea Tradfri) lights. Is it possible to count not individual lights but groups for grouped lights?
Currently lights in groups are numbered as this:
light.kitchen_1
light.kitchen_2
light.kitchen_3
I have max 5 lights in groups. If it helps I can rename these individual lights so I can filter them not by number at end but something like light.kitchen_1_grouped.
currently that light count above is countig all light entities. If kitchen lights and living room light are on, it will count 5 lights (4 individual lights + 1 group). Is it possible to count only group light (when applicable) and not the individual grouped lights? So that in mentioned example only 2 lights are counted (1 group + 1 individual light = living room).
Correct, because a Light Group entity belongs to the light domain.
Probably.
First thing you will need is to distinguish a Light Group entity from a standard Light entity. A Light Group entity has an attribute called entity_id containing a list of its members (a standard Light entity doesn’t have this attribute). You can test for the presence of the entity_id attribute to determine if the entity is a Light Group. Here’s a test that will include Light Group entities and exclude standard Light entities:
selectattr('attributes.entity_id', 'defined')
For example, this will count all the Light Group entities you currently have:
{{ states.light | selectattr('attributes.entity_id', 'defined') | list | count }}
I leave it to you to figure out how to use that in a template to meet your stated requirement.
I got the part to count the group lights that are on.
{% set count = states | selectattr(‚attributes.entity_id‘, ‚defined‘)
| selectattr(„domain“, ‚eq‘, ‚light‘)
| selectattr(‚state‘, ‚eq‘, ‚on‘)
| map(attribute=‚entity_id‘)
| list
| length %}
{{ count }}
But I can’t figure out, how can I count the lights that don’t have attributes.entity_id defined. Or am I going the wrong way?
Update: After posting I’ve got an idea, how to do this other way. I’ve added custom attribute to lights that are grouped and then it’s easy calculation (all lights - grouped lights).
{% set count = states | selectattr('attributes.grouped', 'eq', 'on')
| selectattr('domain', 'eq', 'light')
| selectattr('state', 'eq', 'on')
| map(attribute='entity_id')
| list
| count %}
I went through the full tread, just to make sure I understand… In order to get a constant update, we need to add all relevant entity_ids. Correct ?
If so, the code should something like
- platform: template
sensors:
luci_spente:
entity_id:
- light.light1
- light.light2
value_template: >
{% set domain = 'light' %}
{% set state = 'on' %}
{{states[domain] | selectattr('state','eq', state) | list | count == 0}}