have a set of sensors, and corresponding switches of which I check wether power consumption is not yet 0, while the switch is turned off (this can happen if the wave signal is already processed in the system, but hasnt yet reached the physical switch)
I use a template sensor to show me which sensors are still consuming power:
{%- set ns = namespace(not_off=[]) %}
{%- for s in expand('group.iungo_switches_actueel')
if s.object_id.split('_actueel')[0] not in
['inductieplaat','patchboard_zolder'] and
states(s.entity_id) != '0' and
states('switch.' + s.object_id.split('_actueel')[0]) == 'off' %}
{%- set ns.not_off = ns.not_off + [s.name+ ': ' + s.state + ' watt'] %}
{%- endfor %}
{% set count_not_off = ns.not_off|count %}
{% set list = ns.not_off %}
{% if count_not_off == 0 %} All fine
{%- elif count_not_off == 1 %}
{{list[0]}} is still using power!
{%- elif count_not_off == 2 %}
{{list|join(' and ')}} are still using power!
{%- else %}
{{list[:-1]|join(', ')}}, and {{list[-1]}} are still using power!
{%- endif %}
this works fine.
But, if this sensors is not showing ‘all is fine’ (count != 0) , I would like to have an automatic set of shell commands run for these switches, to force an extra meterget (that’s what it’s called in the ZWave system)
as an experiment, I made this template sensor:
power_using_off_meterget_usage_command:
friendly_name: >
Power using 'off' meterget command
value_template: >
{%- set ns = namespace(not_off=[]) %}
{%- for s in expand('group.iungo_switches_actueel')
if s.entity_id not in
['sensor.inductieplaat_actueel','sensor.patchboard_zolder_actueel'] and
states(s.entity_id) != '0' and
states(s.entity_id.split('_actueel')[0]|replace('sensor','switch'))
== 'off' %}
{%- set ns.not_off = ns.not_off + ['shell_command.' + s.object_id.split('_actueel')[0] + '_meterget_usage'] %}
{%- endfor %}
{{ns.not_off|join(', ')}}
and this outputs a comma separated list of correct shell_commands. Unfortunately, we can’t run that as a service… duh.
so in common tongue, I would need
for all sensors in expand(‘group.iungo_switches_actueel’)
if sensor A is using power, while switch A is ‘off’, run shell_command A_meterget.
Is that at all possible?
please have a look, thanks!