- id: '1749315801894'
  alias: "\U0001F4C5 Notif - Calendrier"
  description: Envoie une notification Gotify à chaque déclenchement d'un événement
    calendrier (bestioles, maison, poubelles, jardin).
  triggers:
  - entity_id:
    - calendar.bestioles
    - calendar.mashome
    - calendar.garbage
    - calendar.garden
    to: 'on'
    trigger: state
  conditions: []
  actions:
  - action: script.notif_gotify
    data:
      title: "\U0001F4C5 {{ state_attr(trigger.entity_id, 'friendly_name') }}"
      message: '{{ state_attr(trigger.entity_id, ''message'') }}'
      priority: 5
  mode: single
- id: '1751221338548'
  alias: "\U0001F680 Système - Home Assistant (MAJ + démarrage + arrêt)"
  description: Notifie les mises à jour disponibles (Core, OS, Supervisor) et les
    événements de cycle de vie de HA (démarrage / arrêt).
  triggers:
  - entity_id:
    - update.home_assistant_core_update
    - update.home_assistant_operating_system_update
    - update.home_assistant_supervisor_update
    to: 'on'
    id: update
    trigger: state
  - event: start
    id: start
    trigger: homeassistant
  - event: shutdown
    id: stop
    trigger: homeassistant
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id: update
      sequence:
      - data:
          title: "\U0001F680 MAJ {{ trigger.to_state.name }}"
          message: Version {{ trigger.to_state.attributes.latest_version }} disponible
          priority: 5
        action: script.notif_gotify
    - conditions:
      - condition: trigger
        id: start
      sequence:
      - data:
          title: ✅ Gérald
          message: Démarrage réussi
          priority: 4
        action: script.notif_gotify
    - conditions:
      - condition: trigger
        id: stop
      sequence:
      - data:
          title: ⏹️ Gérald
          message: Arrêt en cours
          priority: 4
        action: script.notif_gotify
  mode: single
- id: '1752652068313'
  alias: "\U0001F3D6️ Simulation Présence"
  description: 'Simule une présence réaliste pendant les vacances : ouverture progressive
    des volets le matin, fermeture au coucher du soleil, allumage/extinction aléatoire
    des lumières en soirée.'
  triggers:
  - minutes: /30
    trigger: time_pattern
  conditions:
  - condition: state
    entity_id: input_boolean.vacance
    state: 'on'
  actions:
  - choose:
    - conditions:
      - condition: sun
        after: sunrise
        after_offset: +00:30:00
      - condition: time
        before: '10:00:00'
      sequence:
      - action: cover.set_cover_position
        target:
          entity_id:
          - cover.bibliotheque
          - cover.cuisine
          - cover.salle_a_manger
          - cover.salon
        data:
          position: '{{ range(80, 100) | random }}'
  - choose:
    - conditions:
      - condition: sun
        after: sunset
        after_offset: -00:30:00
      sequence:
      - action: cover.close_cover
        target:
          entity_id:
          - cover.bibliotheque
          - cover.cuisine
          - cover.salle_a_manger
          - cover.salon
        data: {}
  - choose:
    - conditions:
      - condition: time
        after: '18:00:00'
        before: '23:30:00'
      - condition: sun
        after: sunset
      sequence:
      - action: light.turn_on
        target:
          entity_id: '{{ [''light.interrupteur_veranda_l1'', ''light.bar'', ''light.plafonnier'',
            ''light.halogene''] | random }}'
        data:
          brightness_pct: '{{ range(40, 80) | random }}'
          transition: 2
      - delay:
          minutes: '{{ range(15, 45) | random }}'
      - action: light.turn_off
        target:
          entity_id: '{{ expand(''light.lumieres'') | selectattr(''state'', ''eq'',
            ''on'') | map(attribute=''entity_id'') | list | random }}'
        data:
          transition: 2
  mode: queued
  max: 3
- id: '1755537503205'
  alias: "\U0001FA9F Volets - Gestion complète"
  description: Ferme les volets en mode canicule (temp >24°C, hors 20h-6h, si volets
    ouverts). Ouvre les volets au lever du soleil si le mode maison est 'absent'.
  triggers:
  - entity_id: input_select.maison_mode
    trigger: state
    id: mode_change
  - entity_id: sensor.mont_cauvaire_temperature
    above: 24
    trigger: numeric_state
    id: temp_canicule
  - trigger: sun
    event: sunrise
    id: sunrise
  conditions: []
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id: temp_canicule
      - condition: not
        conditions:
        - condition: time
          after: '20:00:00'
          before: 06:00:00
      - condition: numeric_state
        entity_id: sensor.mont_cauvaire_temperature
        above: 24
      - condition: state
        entity_id: cover.volets
        state: open
      sequence:
      - action: scene.turn_on
        target:
          entity_id: scene.volets_chaleur
    - conditions:
      - condition: trigger
        id: sunrise
      - condition: state
        entity_id: input_select.maison_mode
        state: absent
      sequence:
      - action: cover.open_cover
        target:
          entity_id: cover.volets
  mode: restart
- id: '1755633804919'
  alias: "\U0001F9F9 Doris - Gestion complète"
  description: Rappel de vidage du réservoir si ≥5 cycles (11h et 19h). Incrémente
    le compteur et notifie à chaque fin de nettoyage.
  triggers:
  - trigger: time
    at: '11:00:00'
    id: notification_matin
  - trigger: time
    at: '19:00:00'
    id: notification_soir
  - trigger: state
    entity_id:
    - vacuum.doris
    from:
    - returning
    to:
    - docked
    id: nettoyage_termine
  conditions: []
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id:
        - notification_matin
        - notification_soir
      - condition: numeric_state
        entity_id: counter.cycle_doris
        above: 5
      sequence:
      - action: script.notif_gotify
        data:
          title: "\U0001F9F9 Doris"
          message: 'Réservoir à vider : {{ states(''counter.cycle_doris'') }} cycles
            effectués'
          priority: 6
    - conditions:
      - condition: trigger
        id: nettoyage_termine
      sequence:
      - action: counter.increment
        target:
          entity_id: counter.cycle_doris
      - action: script.notif_gotify
        data:
          title: "\U0001F9F9 Doris"
          message: Nettoyage terminé ({{ states('counter.cycle_doris') }} cycles)
          priority: 3
  mode: queued
  max: 3
- id: '1755637169948'
  alias: ⏱️ Timer Unifié - TV Chambre et Home Cinéma
  description: 'Gestion centralisée des timers d''extinction : TV chambre (durée configurable
    via input_number) et home cinéma (fixe 1h30). Notifie au démarrage, à l''extinction
    et en cas d''annulation.'
  triggers:
  - entity_id: input_boolean.etat_minuteur_chambre
    to: 'on'
    trigger: state
    id: timer_chambre
  - entity_id: input_boolean.minuteur_salon
    to: 'on'
    trigger: state
    id: timer_salon
  - trigger: state
    entity_id:
    - input_boolean.etat_minuteur_chambre
    to:
    - 'off'
    id: cancel_chambre
  conditions: []
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id:
        - timer_chambre
      sequence:
      - variables:
          delay_minutes: '{{ states(''input_number.timer_ch'') | int(30) }}'
      - action: script.notif_gotify
        data:
          title: ⏱️ Timer TV Chambre
          message: Extinction dans {{ delay_minutes }} minutes
          priority: 3
      - delay:
          minutes: '{{ delay_minutes }}'
      - condition: state
        entity_id: input_boolean.etat_minuteur_chambre
        state: 'on'
      - action: switch.turn_off
        target:
          entity_id:
          - switch.tele_chambre
      - action: input_boolean.turn_off
        target:
          entity_id: input_boolean.etat_minuteur_chambre
      - action: script.notif_gotify
        data:
          title: ✅ Timer terminé
          message: TV chambre éteinte
          priority: 2
    - conditions:
      - condition: trigger
        id:
        - timer_salon
      sequence:
      - action: script.notif_gotify
        data:
          title: ⏱️ Timer Home Cinéma
          message: Extinction dans 1h30
          priority: 3
      - delay:
          hours: 1
          minutes: 30
      - condition: state
        entity_id: input_boolean.minuteur_salon
        state: 'on'
      - action: switch.turn_off
        target:
          entity_id: switch.home_cinema_prise
      - action: input_boolean.turn_off
        target:
          entity_id: input_boolean.minuteur_salon
      - action: script.notif_gotify
        data:
          title: ✅ Timer terminé
          message: Home cinéma éteint
          priority: 2
    - conditions:
      - condition: trigger
        id:
        - cancel_chambre
      sequence:
      - action: script.notif_gotify
        data:
          title: ❌ Timer annulé
          message: Timer chambre annulé
          priority: 2
  mode: parallel
  max: 2
- id: '1758057240516'
  alias: "\U0001F4FA Home Cinéma - Gestion complète"
  description: Synchronise la Bbox, la prise home cinéma et le plafonnier. Gère l'allumage/extinction
    de nuit (lumière ambiante) et adapte le comportement selon l'origine du déclenchement
    (prise ou Bbox).
  triggers:
  - entity_id: switch.home_cinema_prise
    trigger: state
    to: 'on'
    for:
      seconds: 3
    id: TVON
  - entity_id: switch.home_cinema_prise
    trigger: state
    to: 'off'
    id: TVOFF
  - type: turned_on
    device_id: 3b837fd4e120ab9b973f31ce99017ef5
    entity_id: 34b78481039c1e06821015a0e6bed72d
    domain: remote
    trigger: device
    for:
      seconds: 3
    id: bbox_on
  - trigger: sun
    event: sunset
    id: Coucher_soleil
  conditions: []
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id: TVON
      - condition: sun
        after: sunset
        before: sunrise
      sequence:
      - action: remote.turn_on
        target:
          entity_id: remote.bboxtv
      - action: light.turn_on
        data:
          color_temp_kelvin: 2000
          brightness_pct: 50
        target:
          entity_id: light.plafonnier
    - conditions:
      - condition: trigger
        id: TVON
      - condition: sun
        before: sunset
        after: sunrise
      sequence:
      - action: remote.turn_on
        target:
          entity_id: remote.bboxtv
    - conditions:
      - condition: trigger
        id: bbox_on
      - condition: sun
        after: sunset
        before: sunrise
      sequence:
      - action: switch.turn_on
        target:
          entity_id: switch.home_cinema_prise
      - action: light.turn_on
        data:
          color_temp_kelvin: 2000
          brightness_pct: 50
        target:
          entity_id: light.plafonnier
    - conditions:
      - condition: trigger
        id: bbox_on
      - condition: sun
        before: sunset
        after: sunrise
      sequence:
      - action: switch.turn_on
        target:
          entity_id: switch.home_cinema_prise
    - conditions:
      - condition: trigger
        id: Coucher_soleil
      - condition: state
        entity_id: switch.home_cinema_prise
        state: 'on'
      sequence:
      - action: light.turn_on
        data:
          color_temp_kelvin: 2000
          brightness_pct: 50
        target:
          entity_id: light.plafonnier
    - conditions:
      - condition: trigger
        id: TVOFF
      sequence:
      - action: remote.turn_off
        target:
          entity_id: remote.bboxtv
          device_id:
          - 3b837fd4e120ab9b973f31ce99017ef5
          - e40a5194622be081af6b905eaa6675c6
          area_id: salon
        data: {}
      - action: light.turn_off
        target:
          entity_id: light.plafonnier
  mode: restart
- id: '1763205350889'
  alias: "\U0001FA9F Radiateurs + Fenêtres"
  description: Coupe le radiateur chambre si la fenêtre reste ouverte >10s, le rallume
    2min après fermeture. Même logique pour le radiateur bureau via le capteur de
    verrou.
  triggers:
  - entity_id:
    - binary_sensor.fenetre_chambre
    - binary_sensor.verrou_fenetre_bureau
    trigger: state
    for:
      seconds: 10
  conditions: []
  actions:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ trigger.entity_id == ''binary_sensor.fenetre_chambre''
          }}'
      - condition: state
        entity_id: binary_sensor.fenetre_chambre
        state: 'on'
      - condition: template
        value_template: '{{ states(''climate.radiateur_chambre'') != ''off'' }}'
      sequence:
      - action: climate.set_hvac_mode
        target:
          device_id: f8576af3693e3b54af895631c64538fb
        data:
          hvac_mode: 'off'
      - action: script.notif_gotify
        data:
          title: "\U0001FA9F Fenêtre chambre"
          message: Radiateur coupé (fenêtre ouverte)
          priority: 4
        enabled: false
    - conditions:
      - condition: template
        value_template: '{{ trigger.entity_id == ''binary_sensor.fenetre_chambre''
          }}'
      - condition: state
        entity_id: binary_sensor.fenetre_chambre
        state: 'off'
        for:
          seconds: 5
      - condition: template
        value_template: '{{ states(''climate.radiateur_chambre'') == ''off'' }}'
      sequence:
      - delay:
          minutes: 2
      - condition: state
        entity_id: binary_sensor.fenetre_chambre
        state: 'off'
      - condition: template
        value_template: '{{ states(''climate.radiateur_chambre'') == ''off'' }}'
      - action: climate.set_hvac_mode
        target:
          device_id: f8576af3693e3b54af895631c64538fb
        data:
          hvac_mode: heat
      - action: script.notif_gotify
        data:
          title: "\U0001FA9F Fenêtre chambre"
          message: Radiateur rallumé (fenêtre fermée)
          priority: 3
        enabled: false
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ trigger.entity_id == ''binary_sensor.verrou_fenetre_bureau''
          }}'
      - condition: state
        entity_id: binary_sensor.verrou_fenetre_bureau
        state: 'on'
      - condition: state
        entity_id: switch.radiateur_bureau
        state: 'on'
      sequence:
      - action: switch.turn_off
        target:
          entity_id: switch.radiateur_bureau
      - action: script.notif_gotify
        data:
          title: "\U0001FA9F Fenêtre bureau"
          message: Radiateur coupé (fenêtre ouverte)
          priority: 4
        enabled: false
    - conditions:
      - condition: template
        value_template: '{{ trigger.entity_id == ''binary_sensor.verrou_fenetre_bureau''
          }}'
      - condition: state
        entity_id: binary_sensor.verrou_fenetre_bureau
        state: 'off'
        for:
          seconds: 5
      - condition: state
        entity_id: switch.radiateur_bureau
        state: 'off'
      sequence:
      - delay:
          minutes: 2
      - condition: state
        entity_id: binary_sensor.verrou_fenetre_bureau
        state: 'off'
      - condition: state
        entity_id: switch.radiateur_bureau
        state: 'off'
      - action: switch.turn_on
        target:
          entity_id: switch.radiateur_bureau
      - action: script.notif_gotify
        data:
          title: "\U0001FA9F Fenêtre bureau"
          message: Radiateur rallumé (fenêtre fermée)
          priority: 3
        enabled: false
  mode: queued
  max: 5
- id: '1766170300000'
  alias: "\U0001F527 Maintenance et Surveillance"
  description: Surveille les appareils hors ligne (10min), les erreurs Doris (5min),
    les batteries critiques (<10%, heure ouvrable). Rapport batteries faibles (<20%)
    tous les dimanches à 10h.
  triggers:
  - entity_id:
    - vacuum.doris
    - switch.radiateur_bureau
    - switch.home_cinema_prise
    - cover.volets
    - climate.radiateur_chambre
    to: unavailable
    trigger: state
    for:
      minutes: 10
    id: appareil_offline
  - entity_id: vacuum.doris
    to: error
    trigger: state
    for:
      minutes: 5
    id: doris_erreur
  - trigger: numeric_state
    entity_id:
    - sensor.doris_battery_level
    - sensor.porte_bibliotheque
    - sensor.porte_veranda
    - sensor.fenetre_chambre
    - sensor.verrou_fenetre_bureau
    below: 10
    id: batterie_critique
    for:
      hours: 1
  - trigger: state
    entity_id: sensor.litiere_etat_batterie
    to: low
    id: batterie_litiere
    for:
      hours: 1
  - trigger: time
    at: '10:00:00'
    id: rappel_hebdo
  conditions: []
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id: appareil_offline
      sequence:
      - action: script.notif_gotify
        data:
          title: "\U0001F50C Appareil hors ligne"
          message: '{{ trigger.to_state.attributes.friendly_name }} indisponible'
          priority: 8
    - conditions:
      - condition: trigger
        id: doris_erreur
      sequence:
      - action: script.notif_gotify
        data:
          title: "\U0001F9F9 Doris - Erreur"
          message: Doris en erreur depuis 5min
          priority: 8
    - conditions:
      - condition: trigger
        id: batterie_critique
      - condition: template
        value_template: '{{ now().hour >= 8 and now().hour < 22 }}'
      sequence:
      - action: script.notif_gotify
        data:
          title: "\U0001F50B Batterie critique"
          message: '{{ trigger.to_state.attributes.friendly_name }} à {{ trigger.to_state.state
            }}%'
          priority: 8
    - conditions:
      - condition: trigger
        id: batterie_litiere
      sequence:
      - action: script.notif_gotify
        data:
          title: "\U0001F50B Batterie litière"
          message: Batterie du capteur PIR litière faible
          priority: 8
    - conditions:
      - condition: trigger
        id: rappel_hebdo
      - condition: time
        weekday:
        - sun
      sequence:
      - variables:
          batteries_faibles: "{% set ns = namespace(liste=[]) %} {% for entity in
            [\n  'sensor.doris_battery_level',\n  'sensor.porte_veranda',\n  'sensor.porte_bibliotheque',\n
            \ 'sensor.fenetre_chambre',\n  'sensor.verrou_fenetre_bureau'\n] %}\n
            \ {% set niveau = states(entity) | int(100) %}\n  {% if niveau < 20 %}\n
            \   {% set nom = state_attr(entity, 'friendly_name') %}\n    {% set ns.liste
            = ns.liste + [nom ~ ' (' ~ niveau ~ '%)'] %}\n  {% endif %}\n{% endfor
            %} {{ ns.liste | join(', ') }}"
      - condition: template
        value_template: '{{ batteries_faibles != "" }}'
      - action: script.notif_gotify
        data:
          title: "\U0001F50B Rappel batteries"
          message: 'À surveiller : {{ batteries_faibles }}'
          priority: 5
  mode: queued
  max: 5
- id: '1766170300001'
  alias: "\U0001F326️ Météo - Gestion complète"
  description: Alerte en cas de pluie, orage ou neige (après 15min de stabilisation).
    Alerte gel entre 17h et 21h si température <3°C depuis 15min.
  triggers:
  - entity_id:
    - sensor.mont_cauvaire_original_condition
    trigger: state
    id: condition_change
    for:
      hours: 0
      minutes: 15
      seconds: 0
  - entity_id:
    - sensor.mont_cauvaire_temperature
    below: 3
    trigger: numeric_state
    id: risque_gel
    for:
      hours: 0
      minutes: 15
      seconds: 0
  conditions: []
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id:
        - condition_change
      - condition: template
        value_template: '{{ trigger.to_state.state in [''pluie'', ''orage'', ''neige'']
          }}'
      - condition: template
        value_template: '{{ trigger.from_state.state not in [''pluie'', ''orage'',
          ''neige''] }}'
      sequence:
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ trigger.to_state.state == ''orage'' }}'
          sequence:
          - action: script.notif_gotify
            data:
              title: ⛈️ Alerte orage
              message: Rentrer mobilier jardin et fermer fenêtres !
              priority: 8
        default:
        - action: script.notif_gotify
          data:
            title: "\U0001F326️ Alerte météo"
            message: '{{ trigger.to_state.state | capitalize }}'
            priority: 6
    - conditions:
      - condition: trigger
        id:
        - risque_gel
      - condition: time
        after: '17:00:00'
        before: '21:00:00'
      sequence:
      - action: script.notif_gotify
        data:
          title: "\U0001F331 Protection plantes"
          message: Gel prévu ({{ states('sensor.mont_cauvaire_temperature') }}°C)
            - Protéger plantes !
          priority: 7
  mode: queued
  max: 3
- id: '1766573335939'
  alias: "\U0001F431 Litière - Utilisation et notifications"
  description: Détecte chaque passage de Mojo (filtre 15s), incrémente le compteur
    et notifie sur mobile. Déclenche un rappel nettoyage au seuil configuré, et un
    rappel grand nettoyage au seuil de nettoyages cumulés. Reset manuel via input_button.
  triggers:
  - entity_id:
    - binary_sensor.litiere_mouvement
    to:
    - 'on'
    trigger: state
    id: utilisation
    for:
      seconds: '{{ states(''input_number.duree_detection_litiere'') | int(15) }}'
  - entity_id: counter.compteur_litiere
    trigger: state
    id: check_nettoyage
  - entity_id: counter.nettoyages_litiere
    trigger: state
    id: check_gros_nettoyage
  - entity_id: input_button.litiere_reset
    trigger: state
    id: reset
  conditions: []
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id:
        - utilisation
      sequence:
      - action: counter.increment
        target:
          entity_id: counter.compteur_litiere
      - action: notify.mobile_app_arthas
        data:
          title: "\U0001F431 Litière"
          message: Mojo a chié.
    - conditions:
      - condition: trigger
        id:
        - check_nettoyage
      - condition: template
        value_template: "{{ states('counter.compteur_litiere') | int >= \n   states('input_number.seuil_nettoyage_litiere')
          | int }}"
      sequence:
      - action: script.notif_gotify
        data:
          title: "\U0001F9F9 Litière à nettoyer"
          message: Mojo a utilisé la litière {{ states('counter.compteur_litiere')
            }} fois. Il est temps de retirer les crottes !
          priority: 6
      - action: counter.reset
        target:
          entity_id: counter.compteur_litiere
    - conditions:
      - condition: trigger
        id:
        - check_gros_nettoyage
      - condition: template
        value_template: "{{ states('counter.nettoyages_litiere') | int >= \n   states('input_number.seuil_gros_nettoyage')
          | int }}"
      sequence:
      - action: script.notif_gotify
        data:
          title: "\U0001F9FC GROS NETTOYAGE litière"
          message: '{{ states(''counter.nettoyages_litiere'') }} nettoyages effectués
            ! Il est temps de faire le gros nettoyage complet de la litière (changement
            total).'
          priority: 8
      - action: counter.reset
        target:
          entity_id: counter.nettoyages_litiere
      - action: counter.reset
        target:
          entity_id: counter.compteur_litiere
    - conditions:
      - condition: trigger
        id:
        - reset
      sequence:
      - action: counter.reset
        target:
          entity_id: counter.compteur_litiere
  mode: queued
  max: 3
- id: '1771693177609'
  alias: "\U0001F4A1 Lumières - Gestion complète"
  description: Allume la véranda et le bar à l'arrivée d'un habitant après le coucher
    du soleil (extinction véranda après 5min). Allume l'allée si une ouverture est
    détectée de nuit.
  triggers:
  - entity_id:
    - person.morgane
    - person.seb
    zone: zone.home
    event: enter
    id: arrivee
    trigger: zone
  - entity_id:
    - binary_sensor.fenetre_bibliotheque
    - binary_sensor.porte_veranda
    to: 'on'
    id: ouverture
    trigger: state
  conditions: []
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id: arrivee
      - condition: sun
        after: sunset
      sequence:
      - target:
          entity_id:
          - light.bar
          - light.interrupteur_veranda_l1
        data:
          brightness_pct: 100
        action: light.turn_on
      - delay: 00:05:00
      - target:
          entity_id: light.interrupteur_veranda_l1
        action: light.turn_off
        data: {}
    - conditions:
      - condition: trigger
        id: ouverture
      - condition: state
        entity_id: sun.sun
        state: below_horizon
      sequence:
      - target:
          entity_id: switch.allee
        action: switch.turn_on
        data: {}
      - delay: 00:05:00
      - target:
          entity_id: switch.allee
        action: switch.turn_off
        data: {}
  mode: restart
- id: '1777000000001'
  alias: "\U0001F3E0 Mode Maison - Gestion complète"
  description: Met à jour input_select.maison_mode selon la présence de Morgane et
    Seb et l'état du mode vacances. Désactive automatiquement les vacances au retour
    d'un habitant.
  triggers:
  - entity_id: person.morgane
    zone: zone.home
    event: enter
    trigger: zone
    id: morgane_enter
  - entity_id: person.morgane
    zone: zone.home
    event: leave
    trigger: zone
    id: morgane_leave
  - entity_id: person.seb
    zone: zone.home
    event: enter
    trigger: zone
    id: seb_enter
  - entity_id: person.seb
    zone: zone.home
    event: leave
    trigger: zone
    id: seb_leave
  - entity_id: input_boolean.vacance
    trigger: state
    id: vacance_toggle
  conditions: []
  actions:
  - choose:
    - alias: Retour maison pendant vacances → désactive vacances
      conditions:
      - condition: or
        conditions:
        - condition: trigger
          id: morgane_enter
        - condition: trigger
          id: seb_enter
      - condition: state
        entity_id: input_boolean.vacance
        state: 'on'
      sequence:
      - action: input_boolean.turn_off
        target:
          entity_id: input_boolean.vacance
      - action: alarmo.disarm
        data:
          code: '4212'
    - alias: Vacances activées → mode vacances + armer Alarmo
      conditions:
      - condition: trigger
        id: vacance_toggle
      - condition: state
        entity_id: input_boolean.vacance
        state: 'on'
      sequence:
      - action: input_select.select_option
        target:
          entity_id: input_select.maison_mode
        data:
          option: vacances
      - action: alarmo.arm
        data:
          mode: vacation
          code: '4212'
    - alias: Vacances OFF + quelqu'un à la maison → mode maison + désarmer
      conditions:
      - condition: or
        conditions:
        - condition: trigger
          id: morgane_enter
        - condition: trigger
          id: seb_enter
      - condition: state
        entity_id: input_boolean.vacance
        state: 'off'
      - condition: template
        value_template: '{{ is_state(''person.morgane'', ''home'') or is_state(''person.seb'',
          ''home'') }}'
      sequence:
      - action: input_select.select_option
        target:
          entity_id: input_select.maison_mode
        data:
          option: maison
      - action: alarmo.disarm
        data:
          code: '4212'
    - alias: Vacances OFF + tout le monde absent → mode absent + armer
      conditions:
      - condition: or
        conditions:
        - condition: trigger
          id: morgane_leave
        - condition: trigger
          id: seb_leave
      - condition: state
        entity_id: input_boolean.vacance
        state: 'off'
      - condition: template
        value_template: '{{ is_state(''person.morgane'', ''not_home'') and is_state(''person.seb'',
          ''not_home'') }}'
      sequence:
      - action: input_select.select_option
        target:
          entity_id: input_select.maison_mode
        data:
          option: absent
      - action: alarmo.arm
        data:
          mode: away
          code: '4212'
  mode: restart
- id: '1781010467486'
  alias: "\U0001F33F Marcelino - Gestion complète"
  description: 'Notifie les erreurs, la batterie faible et le bilan du soir (19h15
    : retour en cours, erreur ou non en charge). Confirme le retour en base après
    19h15.'
  triggers:
  - id: erreur_change
    entity_id: sensor.marcelino_erreur
    trigger: state
  - id: batterie_basse
    entity_id:
    - sensor.marcelino_batterie
    below: 3
    trigger: numeric_state
  - id: soir
    at: '19:15:00'
    trigger: time
  - id: docked
    entity_id: lawn_mower.marcelino
    from: returning
    to: docked
    for:
      seconds: 15
    trigger: state
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id: erreur_change
      - condition: template
        value_template: '{{ erreur != ''no_error'' }}'
      sequence:
      - data:
          title: "\U0001F33F Marcelino"
          message: '❌ Erreur : {{ erreur }}'
          priority: 9
        action: script.notif_gotify
    - conditions:
      - condition: trigger
        id: batterie_basse
      sequence:
      - data:
          title: "\U0001F33F Marcelino"
          message: "\U0001F50B Batterie faible : {{ states('sensor.marcelino_batterie')
            }}%"
          priority: 7
        action: script.notif_gotify
    - conditions:
      - condition: trigger
        id: soir
      - condition: not
        conditions:
        - condition: state
          entity_id: lawn_mower.marcelino
          state: docked
      sequence:
      - choose:
        - conditions:
          - condition: state
            entity_id: lawn_mower.marcelino
            state: returning
          sequence:
          - data:
              title: "\U0001F33F Marcelino"
              message: "\U0001F3E0 Marcelino est sur le chemin du retour"
              priority: 5
            action: script.notif_gotify
        - conditions:
          - condition: template
            value_template: '{{ erreur != ''no_error'' }}'
          sequence:
          - data:
              title: "\U0001F33F Marcelino"
              message: '❌ Erreur soir : {{ erreur }}'
              priority: 9
            action: script.notif_gotify
        - conditions:
          - condition: template
            value_template: '{{ tension < 25 }}'
          sequence:
          - data:
              title: "\U0001F33F Marcelino"
              message: ⚠️ Non en charge
              priority: 7
            action: script.notif_gotify
    - conditions:
      - condition: trigger
        id: docked
      - condition: time
        after: '19:15:00'
      sequence:
      - data:
          title: "\U0001F33F Marcelino"
          message: ✅ Marcelino est rentré à la maison
          priority: 5
        action: script.notif_gotify
  variables:
    erreur: '{{ states(''sensor.marcelino_erreur'') }}'
    tension: '{{ states(''sensor.marcelino_batterie'') | float(0) }}'
  mode: restart
- id: '1781032426339'
  alias: "\U0001F37D️ Mealie - Sync menus semaine"
  description: Synchronise les menus Mealie — utilise la date de référence si définie
  triggers:
  - trigger: time
    at: 06:00:00
  - trigger: homeassistant
    event: start
  - trigger: state
    entity_id: input_datetime.mealie_semaine_ref
  conditions: []
  actions:
  - variables:
      ref_date: "{% set ref = states('input_datetime.mealie_semaine_ref') %} {% if
        ref not in ['unknown','unavailable',''] %}\n  {% set d = strptime(ref, '%Y-%m-%d')
        %}\n  {{ (d.date() - timedelta(days=d.weekday())).strftime('%Y-%m-%d') }}\n{%
        else %}\n  {{ (now().date() - timedelta(days=now().weekday())).strftime('%Y-%m-%d')
        }}\n{% endif %}"
  - repeat:
      for_each:
      - nom: lundi
        offset: 0
      - nom: mardi
        offset: 1
      - nom: mercredi
        offset: 2
      - nom: jeudi
        offset: 3
      - nom: vendredi
        offset: 4
      - nom: samedi
        offset: 5
      - nom: dimanche
        offset: 6
      sequence:
      - variables:
          jour_nom: '{{ repeat.item.nom }}'
          jour_date: '{{ (strptime(ref_date, ''%Y-%m-%d'').date() + timedelta(days=repeat.item.offset)).strftime(''%Y-%m-%d'')
            }}'
      - repeat:
          for_each:
          - nom: petit_dejeuner
            entity: calendar.mealie_petit_dejeuner
          - nom: dejeuner
            entity: calendar.mealie_dejeuner
          - nom: accompagnement
            entity: calendar.mealie_accompagnement
          - nom: collation
            entity: calendar.mealie_collation
          - nom: dessert
            entity: calendar.mealie_dessert
          - nom: diner
            entity: calendar.mealie_diner
          sequence:
          - action: calendar.get_events
            target:
              entity_id: '{{ repeat.item.entity }}'
            data:
              start_date_time: '{{ jour_date }}T00:00:00'
              end_date_time: '{{ jour_date }}T23:59:59'
            response_variable: events
          - action: input_text.set_value
            target:
              entity_id: input_text.mealie_{{ jour_nom }}_{{ repeat.item.nom }}
            data:
              value: "{% set cal = repeat.item.entity %} {% if events[cal] is defined
                and events[cal].events | length > 0 %}\n  {{ events[cal].events[0].summary
                }}\n{% else %}\n  \n{% endif %}\n"
  mode: single
- id: '1781126730091'
  alias: Alarmo - Alertes Alexa simples
  triggers:
  - entity_id: alarm_control_panel.alarmo
    to: armed_away
    id: armed
    trigger: state
  - entity_id: alarm_control_panel.alarmo
    to: disarmed
    id: disarmed
    trigger: state
  - entity_id: alarm_control_panel.alarmo
    to: triggered
    id: triggered
    trigger: state
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id: armed
      sequence:
      - data:
          target:
          - media_player.echo_chambre
          - media_player.echo_bureau
          - media_player.echo_salon
          message: Système armé.
          data:
            type: announce
        action: notify.alexa_media
    - conditions:
      - condition: trigger
        id: disarmed
      sequence:
      - data:
          target:
          - media_player.echo_chambre
          - media_player.echo_bureau
          - media_player.echo_salon
          message: Système désarmé.
          data:
            type: announce
        action: notify.alexa_media
    - conditions:
      - condition: trigger
        id: triggered
      sequence:
      - data:
          target:
          - media_player.echo_chambre
          - media_player.echo_bureau
          - media_player.echo_salon
          message: Alerte intrusion. Alarme déclenchée.
          data:
            type: announce
        action: notify.alexa_media
        enabled: true
      - action: notify.mobile_app_tablette
        metadata: {}
        data:
          message: Intrusion détectée
          title: "\U0001F6A8 Alarme"
  mode: single
- id: '1781519588436'
  alias: "\U0001F514 Michelle - Gestion minuteur"
  description: Capture la source et notifie en boucle jusqu'à confirmation
  triggers:
  - event_type: assist_pipeline_run
    id: capture_source
    trigger: event
  - event_type: timer.finished
    id: timer_fini
    trigger: event
  actions:
  - choose:
    - conditions:
      - condition: trigger
        id: capture_source
      sequence:
      - action: input_text.set_value
        target:
          entity_id: input_text.timer_source_device
        data:
          value: '{{ trigger.event.data.device_id }}'
    - conditions:
      - condition: trigger
        id: timer_fini
      sequence:
      - action: input_boolean.turn_on
        target:
          entity_id: input_boolean.timer_actif
      - repeat:
          while:
          - condition: state
            entity_id: input_boolean.timer_actif
            state: 'on'
          sequence:
          - action: 'notify.{{ states(''input_text.timer_source_device'') }}

              '
            data:
              title: ⏰ Minuteur terminé !
              message: Dis Okay Nabu, arrête le minuteur
              data:
                channel: timer
                importance: high
                ttl: 0
                priority: high
                persistent: true
                tag: timer_alert
          - delay:
              seconds: 30
- id: '1781627636620'
  alias: "\U0001F4BE Backup Git hebdomadaire"
  description: Sauvegarde la config HA vers Gitea chaque dimanche à 3h
  triggers:
  - trigger: time
    at: 03:00:00
  conditions:
  - condition: time
    weekday:
    - sun
  actions:
  - action: script.git_backup
  mode: single
