Advertisement
Wykop

Kto w domu /Ile osób w domu

Jan 2nd, 2023 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1.  
  2. Wymaga stworzenia grupy domowników
  3. group.awesome_people = moja nazwa grupy domowników ( nazwa do edycji/podmiany)
  4. Grupę można stworzyć za pomocą HA > ustawienia > "Pomocnicy"
  5. person1
  6. person2
  7. ...
  8. #################################################
  9. W template.yaml
  10. #################################################
  11. - sensor:
  12.  
  13. name: Kto w domu
  14. unique_id: kto_w_domu
  15. state: >
  16. {%- set people = expand('group.awesome_people') %}
  17. {{ people | selectattr('state', 'in', ['home', 'on'] ) | list | count }}
  18. icon: >
  19. {%- set icons = ['account-off', 'account', 'account-multiple'] %}
  20. {%- set people = expand('group.awesome_people') %}
  21. {%- set cnt = people | selectattr('state', 'in', ['home', 'on'] ) | list | count %}
  22. {%- if cnt >= 0 %}
  23. mdi:{{ icons[cnt] if cnt in range(icons | count) else 'account-group' }}
  24. {%- else %}
  25. mdi:account-alert
  26. {%- endif %}
  27. attributes:
  28. template: "template"
  29. osoby: >
  30. {%- set people = expand('group.awesome_people') | selectattr('state', 'eq', 'home') | map(attribute='name') | list %}
  31. {%- set company = expand('group.awesome_people') | selectattr('state', 'eq', 'on') | map(attribute='name') | list %}
  32. {%- set people = people + company %}
  33. {{ people }}
  34. A_i_B: >
  35. {%- set people = expand('group.awesome_people') | selectattr('state', 'eq', 'home') | map(attribute='name') | list %}
  36. {%- set company = expand('group.awesome_people') | selectattr('state', 'eq', 'on') | map(attribute='name') | list %}
  37. {%- set people = people + company %}
  38. {%- if people | count > 0 %}
  39. {{- [people[:-1] | join(', '), 'i', people[-1]] | join(' ') if people | count > 1 else people[0] }}
  40. {%- else %}unknown
  41. {%- endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement