Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias: Состояние датчиков и сущностей (недоступны)
- description: ""
- trigger:
- - platform: time_pattern
- hours: /2
- - platform: event
- event_type: telegram_command
- event_data:
- command: /Датчики
- condition:
- - condition: time
- after: "06:00:00"
- before: "23:00:00"
- - condition: template
- value_template: |-
- {% set ns = namespace(counter = 0) -%}
- {% set domains = ['sensor', 'binary_sensor', 'switch','light'] -%}
- {%- for domain in domains -%}
- {%- for item in states[domain] if ((item.state == "unavailable") or (item.state == "unknown")) -%}
- {%- set ns.counter = ns.counter + 1 -%}
- {%- endfor %}
- {%- endfor %}
- {{ ns.counter > 0 }}
- action:
- - service: notify.me
- data:
- message: >
- Следующие датчики и сущности недоступны: {%- set domains = ['sensor',
- 'binary_sensor', 'light', 'switch'] %}
- {% for domain in domains %}
- {%- for item in states[domain] if ((item.state == "unavailable") or (item.state == "unknown")) %}
- {{ item.name }}
- {%- endfor -%}
- {% endfor %}
- - if:
- - condition: template
- value_template: |-
- {{ states.automation
- | selectattr('attributes.current', 'eq', 1) | list | count > 0 }}
- - condition: template
- value_template: |-
- {% set ns = namespace(counter = 0) -%}
- {% for state in states.automation
- | selectattr('attributes.current','defined')
- | selectattr('attributes.current','==', 1)
- | selectattr('attributes.last_triggered', 'defined')
- | selectattr('attributes.last_triggered')
- | sort(attribute='attributes.last_triggered') -%}
- {%- set time_now = now() | as_timestamp(now()) -%}
- {%- set time_triggered = state.attributes.last_triggered | as_timestamp(now()) -%}
- {%- set t = time_now - time_triggered -%}
- {% if t > 3600 %}
- {%- set ns.counter = ns.counter + 1 -%}
- {%- endif -%}
- {% endfor %}
- {{ ns.counter > 0 }}
- enabled: false
- - condition: template
- value_template: |2-
- {% set number = states.automation
- | selectattr('attributes.current','defined')
- | selectattr('attributes.current','==', 1)
- | selectattr('attributes.last_triggered', 'defined')
- | selectattr('attributes.last_triggered', '<', now() - timedelta(hours=1))
- | sort(attribute='attributes.last_triggered')
- | map(attribute='entity_id')
- | list | length %}
- {{number > 0 }}
- then:
- - variables:
- auto_name: >-
- {% set automations = states.automation
- | selectattr('attributes.current','defined')
- | selectattr('attributes.current','==', 1)
- | selectattr('attributes.last_triggered', 'defined')
- | selectattr('attributes.last_triggered', '<', now() - timedelta(hours=1))
- | sort(attribute='attributes.last_triggered')
- | list %}
- {% for automation in automations %}
- {% set name = automation.attributes.friendly_name -%}
- {% set time = automation.attributes.last_triggered | as_timestamp |
- timestamp_custom('%H:%M') -%}
- {{name}}, запущена в {{time}} часов
- {%- endfor %}
- - service: telegram_bot.send_message
- data:
- message: |
- Запущенные более часа назад автоматизации:
- {{auto_name}}
- target: 11111111111
- inline_keyboard:
- - Перезагрузить автоматизации {{"\U0001F503"}}:/reload
- - if:
- - condition: template
- value_template: >-
- {% set cameras = ['dahua', 'yard_side', 'yard_above', 'street',
- 'entrance'] %}
- {% set camera_name = {'sensor.dahua_camera_fps': 'Домофон',
- 'sensor.yard_side_camera_fps': 'Двор сбоку',
- 'sensor.yard_above_camera_fps': 'Двор сверху',
- 'sensor.street_camera_fps': 'Улица', 'sensor.entrance_camera_fps':
- 'Вход'} %}
- {% set ns = namespace(list_camera=[]) %}
- {% for camera in cameras %}
- {%- if states("sensor." + camera + "_camera_fps") == "0" and
- (as_timestamp(now()) - as_timestamp(states.sensor[camera + '_camera_fps'].last_updated)) > 3600 %}
- {%- set ns.list_camera = ns.list_camera + [camera_name['sensor.' + camera + '_camera_fps']] %}
- {%- endif %}
- {% endfor %}
- {{ ns.list_camera | length > 0 }}
- then:
- - variables:
- list_camera: >
- {% set cameras = ['dahua', 'yard_side', 'yard_above', 'street',
- 'entrance'] %}
- {% set camera_name = {'sensor.dahua_camera_fps': 'Домофон',
- 'sensor.yard_side_camera_fps': 'Двор сбоку',
- 'sensor.yard_above_camera_fps': 'Двор сверху',
- 'sensor.street_camera_fps': 'Улица', 'sensor.entrance_camera_fps':
- 'Вход'} %}
- {% set ns = namespace(list_camera=[]) %}
- {% for camera in cameras %}
- {%- if states("sensor." + camera + "_camera_fps") == "0" and
- (as_timestamp(now()) - as_timestamp(states.sensor[camera + '_camera_fps'].last_updated)) > 3600 %}
- {%- set ns.list_camera = ns.list_camera + [camera_name['sensor.' + camera + '_camera_fps']] %}
- {%- endif %}
- {% endfor %}
- {{ ns.list_camera }}
- - service: telegram_bot.send_message
- data:
- message: |
- {% if list_camera | length == 1 %}
- Камера <a href="https://xxxxxx.xxxxxxx">'{{ list_camera | join(', ') }}' </a> не работает.
- {% else %}
- Камеры: <a href="https://xxxxxxxx.xxxxxxxxx">'{{ list_camera | join(', ') }}' </a> не работают.
- {%- endif %}
- target: 1111111111
- mode: single
Advertisement
Add Comment
Please, Sign In to add comment