Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low battery themplate #111

Open
BeardedTinker opened this issue Dec 12, 2023 · 1 comment
Open

Low battery themplate #111

BeardedTinker opened this issue Dec 12, 2023 · 1 comment
Assignees
Labels
Enhancement New feature or request Notification Everything related to notifications

Comments

@BeardedTinker
Copy link
Owner

To accompany video To-Do lists, here is code used in automation:

For trigger, this is used:

platform: template
value_template: |2-
      {% for state in states.sensor | selectattr('attributes.device_class', '==', 'battery') %}
        {% if 0 <= state.state | int(-1) < 20 | int  %}
          {% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ ' %)'] %}
        {% endif %}
      {% endfor %}

And in action, following code is used:

service: todo.add_item
target:
  entity_id: todo.shopping_list_2
data:
  item: >-
    {% set result = namespace(sensors=[]) %} {% for state in states.sensor |
    selectattr('attributes.device_class', '==', 'battery') %}
      {% if 0 <= state.state | int(-1) < 10 | int  %}
        {% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ ' %)'] %}
      {% endif %}
    {% endfor %} {% for state in states.binary_sensor |
    selectattr('attributes.device_class', '==', 'battery') | selectattr('state',
    '==', 'on') %}
        {% set result.sensors = result.sensors + [state.name] %}
    {% endfor %} {{result.sensors|join(', ')}}

This will push to To-Do list called todo.shopping_list_2 list of all entities (names) that have battery power between 0 and 20%

@BeardedTinker BeardedTinker added Enhancement New feature or request Notification Everything related to notifications labels Dec 12, 2023
@BeardedTinker BeardedTinker self-assigned this Dec 12, 2023
Copy link

stale bot commented Mar 13, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Notification Everything related to notifications
Projects
None yet
Development

No branches or pull requests

1 participant