Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 103644

Exclude entities from a variable

$
0
0

Hi all,

I have a automation that is working but want exclude some things:

{% set ns = namespace(battery=[]) %}
{% for s in states.sensor if 'battery_level' in s.entity_id %}
  {% set ns.battery = ns.battery + [s] %}
{% endfor %}
{{ ns.battery | map(attribute='entity_id') | list }}

Result:
['sensor.bathroom2_battery_level', 'sensor.bathroom_battery_level', 'sensor.bedroom_battery_level', 'sensor.bedroom_door_battery_level', 'sensor.diningroom_battery_level', 'sensor.diningroom_door_battery_level', 'sensor.frondoor_door_battery_level', 'sensor.galaxy_tab_a_battery_level', 'sensor.hallway_battery_level', 'sensor.imac_door_battery_level', 'sensor.kitchen_battery_level', 'sensor.livingroom_battery_level', 'sensor.martine_mobile_battery_level', 'sensor.nest_protect_bedroom_battery_level', 'sensor.nest_protect_dining_room_battery_level', 'sensor.nest_protect_living_room_battery_level', 'sensor.ns_telefoon_battery_level', 'sensor.peter_iphone_battery_level', 'sensor.sm_t510_battery_level', 'sensor.toilet_battery_level']

I want exclude in the automation (whole automation below):

sensor.ns_telefoon_battery_level
sensor.sm_t510_battery_level
sensor.martine_mobile_battery_level
value_template: "{{ states(battrery_current) not in ['martine_mobile','galaxy_tab','sm_t510','ns_telefoon'] }}"

But seems its not exclude the entities. Can someone assist me?

- id: "f152dde2-643e-4269-bd7e-d5a11ba98a68"
  alias: "Notification - Low battery nodes"
  trigger:
    - platform: time
      at: "17:00:00"

  variables:
    min_battery_level: 50
    battery_ids: ""
    battrery_current: ""

  condition: []
  
  action:
    - variables:
        battery_ids: >
          {% set ns = namespace(battery=[]) %}
          {% for s in states.sensor if 'battery_level' in s.entity_id %}
            {% set ns.battery = ns.battery + [s] %}
          {% endfor %}
          {{ ns.battery | map(attribute='entity_id') | list }}

    - alias: Repeat

      repeat:
        count: "{{ battery_ids | length }}"

        sequence:
          - variables:
              battrery_current: "{{ battery_ids[repeat.index - 1] }}"
          - condition: template
            value_template: "{{ states(battrery_current) not in ['iphone','ipad','martine_mobile','galaxy_tab','sm_t510','ns_telefoon'] }}"

          - condition: template
            value_template: "{{ 0 < (states(battrery_current) | float) < (min_battery_level | float ) }}"

          - service: script.mobile_notify_no_actionable
            data:
              title: "Battery level low"
              message: "Battery level of {{ state_attr(battrery_current,'friendly_name') }}: {{ states(battrery_current) }}%!"
              thread_id: "system_notification"

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 103644

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>