I have this code that counts all my smart bulbs and show number of turned On Bulbs im my home, which works perfectly. It’s only counts bulbs, but i also have couple of smart sockets with normal bulbs
switch.lamp_socket_1
switch.lamp_socket_2
switch.lamp_socket_3
that i would like to count them togather with the bulbs.
This is My Code:
# lights of count
- platform: template
sensors:
lights_of_count:
friendly_name: 'lights of count 1 floor'
unique_id: lights_of_count
value_template: >
{%- set search_state = 'on' %}
{%- set search_areas = ['My Home Area'] %}
{%- set ns = namespace(lights=[]) %}
{%- for light in states.light | selectattr('state','eq', search_state) %}
{%- for area in search_areas %}
{% if area_name(light.entity_id) == area and "1 floor" not in state_attr(light.entity_id, "friendly_name") %}
{%- set ns.lights = ns.lights + [ light.entity_id ] %}
{% endif%}
{%- endfor %}
{%- endfor %}
{{ ns.lights| list | length }}
i’m kinda new to HA, any idea how i can achieve that.