Advertisement
energywave

Per Alberto Terzo - evento state_changed

Sep 20th, 2022 (edited)
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.43 KB | None | 0 0
  1. automation:
  2.   - id: e43f1a0a-6625-4830-b372-7c62c048c919
  3.     alias: Alexa luci rimaste accese (evento sul gruppo luci)
  4.     mode: parallel
  5.     max: 10
  6.     trigger:
  7.       - platform: event
  8.         event_type: state_changed
  9.     condition:
  10.      - "{{ trigger.event.data.entity_id.startswith('light.') }}"
  11.       - "{{ trigger.event.data.new_state.state == 'on' }}"
  12.       - "{{ trigger.event.data.entity_id in expand(states['group.tutte_le_luci']) | map(attribute='entity_id') | list }}"
  13.       - condition: time
  14.         after: "07:00:00"
  15.         before: "22:00:00"
  16.     action:
  17.       - wait_template: "{{ is_state(trigger.event.data.entity_id, 'off') }}"
  18.         timeout: 00:01:00
  19.       - if:
  20.          - "{{ is_state(trigger.event.data.entity_id, 'on') }}"
  21.         then:
  22.           - alias: "Richiamo script spegnimento tramite actionable"
  23.             service: script.turn_on
  24.             target:
  25.               entity_id: script.light_actionable_turn_off
  26.             data:
  27.               variables:
  28.                 target: "{{ trigger.event.data.entity_id }}"
  29.  
  30. script:
  31.   light_actionable_turn_off:
  32.     alias: "Richiede se spegenre una luce"
  33.     description: "Richiede tramite Alexa Actionable Notification se spegnere una luce"
  34.     mode: queued
  35.     max: 10
  36.     fields:
  37.       target:
  38.         name: "Luce da spegnere"
  39.         description: "Indica la luce da spegnere tramite richiesta con Alexa Actionable Notification"
  40.         selector:
  41.           entity:
  42.             domain: light
  43.         example: "light.strip_soggiorno"
  44.     sequence:
  45.       - service: notify.notify
  46.         data:
  47.           message: >
  48.            Mi risulta che la luce {{ state_attr(target, "friendly_name") }} sia rimasta accesa. Vuoi spegnerla?
  49.       - service: script.activate_alexa_actionable_notification
  50.         data:
  51.           alexa_device: "{{ states('sensor.last_alexa') }}"
  52.           event_id: actionable_notification_prova_luce
  53.           text: >
  54.            Mi risulta che la luce {{ state_attr(target, "friendly_name") }} sia rimasta accesa. Vuoi spegnerla?
  55.       - wait_for_trigger:
  56.         - platform: event
  57.           event_type: alexa_actionable_notification
  58.           id: ResponseYes
  59.           event_data:
  60.             event_id: actionable_notification_prova_luce
  61.             event_response: ResponseYes
  62.         - platform: event
  63.           event_type: alexa_actionable_notification
  64.           id: ResponseNo
  65.           event_data:
  66.             event_id: actionable_notification_prova_luce
  67.             event_response: ResponseNo
  68.         timeout:
  69.           hours: 0
  70.           minutes: 0
  71.           seconds: 15
  72.           milliseconds: 0
  73.         continue_on_timeout: false
  74.       - choose:
  75.         - conditions:
  76.          - "{{ wait.trigger.event.data.event_response_type == 'ResponseYes'}}"
  77.           sequence:
  78.           - service: notify.alexa_media
  79.             data:
  80.               target: "{{ states('sensor.last_alexa') }}"
  81.               data:
  82.                 type: tts
  83.               message: ok
  84.           - service: light.turn_off
  85.             target:
  86.               entity_id: "{{ target }}"
  87.         - conditions:
  88.           - condition: template
  89.             value_template: "{{ wait.trigger.event.data.event_response_type == 'ResponseNo'}}"
  90.           sequence:
  91.           - service: notify.alexa_media
  92.             data:
  93.               target: "{{ states('sensor.last_alexa') }}"
  94.               data:
  95.                 type: tts
  96.               message: ok
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement