calas

Rilevamento automatico ospiti

Jun 30th, 2022 (edited)
547
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.65 KB | None
  1. ################################################################################
  2. ##                  Sensor
  3. ################################################
  4. sensor:
  5.   - platform: template
  6.     sensors:
  7.       netatmo_type:
  8.         friendly_name: Netatmo tipo di rilevamento
  9.         value_template: >
  10.          {%- if is_state("sensor.nacamera_tipo_evento", "person") %}
  11.               Persone
  12.           {%- elif is_state("sensor.nacamera_tipo_evento", "movement") %}
  13.               Movimento
  14.           {%- elif is_state("sensor.nacamera_tipo_evento", "changed") %}
  15.               Info
  16.           {% endif %}
  17.         icon_template: >
  18.          {%- if is_state("sensor.nacamera_tipo_evento", "person") %}
  19.               mdi:account-star
  20.           {%- elif is_state("sensor.nacamera_tipo_evento", "movement") %}
  21.               mdi:motion-sensor
  22.           {%- elif is_state("sensor.nacamera_tipo_evento", "topology_changed") %}
  23.               mdi:information-variant
  24.           {% endif %}
  25.  
  26.       ospiti_count:
  27.         friendly_name: conteggio ospiti
  28.         value_template: >-
  29.           {{ states.device_tracker | selectattr('state', 'eq', 'home') | selectattr('attributes.ssid', 'eq', 'LAN SOLO OSPITI') | list | count }}
  30.  
  31. ################################################################################
  32. ##                  Binary Sensor
  33. ################################################
  34. binary_sensor:
  35.   - platform: template
  36.     sensors:
  37.       netatmo_rilevamento_ospiti:
  38.         device_class: presence
  39.         friendly_name: Netatmo rilevamento ospiti
  40.         value_template: >
  41.          {%- if is_state("sensor.nacamera_tipo_evento", "person") %}
  42.             {%- if is_state("sensor.nacamera_conosciuto", "True") %}
  43.               {% if states("sensor.nacamera_name") != "Francesco" and states('sensor.nacamera_name') != 'Simona' and states('sensor.nacamera_name') != 'Gaia' and states('sensor.nacamera_name') != 'Emma' %}
  44.                 true
  45.               {% else %}
  46.                 false
  47.               {% endif %}
  48.             {% else %}
  49.               false
  50.             {% endif %}
  51.           {% else %}
  52.             false
  53.           {% endif %}
  54.  
  55. ################################################################################
  56. ##                  Template
  57. ################################################
  58. template:
  59.   - trigger:
  60.       - platform: event
  61.         event_type: netatmo_event
  62.     sensor:
  63.       - name: "NACamera name"
  64.         state: "{{trigger.event.data['data']['name'] | default('nessuno')}}"
  65.       - name: "NACamera conosciuto"
  66.         state: "{{trigger.event.data['data']['is_known'] | default('false')}}"
  67.       - name: "NACamera tipo evento"
  68.         state: "{{trigger.event.data['data']['event_type']}}"
  69.     binary_sensor:
  70.       - name: rilevamento ospiti check
  71.         auto_off: 15
  72.         state: "true"
  73.  
  74. ################################################################################
  75. ##                  Automation
  76. ################################################
  77. automation:
  78.   - alias: Netatmo Event
  79.     description: Eventi Netatmo
  80.     trigger:
  81.       - event_data: {}
  82.         event_type: netatmo_event
  83.         platform: event
  84.     action:
  85.       - condition: template
  86.         value_template: "{{ trigger.event.data['data']['event_type'] == 'person' }}"
  87.       - service: notify.netatmo_log
  88.         data_template:
  89.           message: "[{{ now().strftime('%d/%m/%Y - %H:%M') }}] - {{ trigger.event.data.data.name }}"
  90.  
  91.   - alias: Netatmo modo ospiti auto on
  92.     description: Eventi Netatmo
  93.     trigger:
  94.       - platform: state
  95.         entity_id: binary_sensor.netatmo_rilevamento_ospiti
  96.         to: "on"
  97.       - platform: template
  98.         value_template: "{{ states('sensor.ospiti_count') > '0' }}"
  99.     condition:
  100.       - condition: state
  101.         entity_id: input_boolean.riconoscimento_ospiti
  102.         state: "on"
  103.       - condition: state
  104.         entity_id: group.famiglia
  105.         state: "home"
  106.     action:
  107.       service: input_boolean.turn_on
  108.       entity_id: input_boolean.modo_ospite
  109.  
  110.   - alias: Netatmo modo ospiti auto off
  111.     description: Eventi Netatmo
  112.     mode: restart
  113.     max_exceeded: silent
  114.     trigger:
  115.       - platform: state
  116.         entity_id: binary_sensor.netatmo_rilevamento_ospiti
  117.         to: "off"
  118.         for:
  119.           minutes: 15
  120.       - platform: state
  121.         entity_id: binary_sensor.rilevamento_ospiti_check
  122.         to: "off"
  123.     condition:
  124.       condition: state
  125.       entity_id: binary_sensor.netatmo_rilevamento_ospiti
  126.       state: "off"
  127.     action:
  128.       - wait_template: "{{ states('sensor.ospiti_count') == '0' }}"
  129.       - service: input_boolean.turn_off
  130.         entity_id: input_boolean.modo_ospite
  131.  
RAW Paste Data Copied