Packages: !include_dir_named .packages

Bonjour, pour ceux qui utilisent le packagés pour ranger les fichiers etc…
Je qu’elle petit problème pour crée des binary sensor.qui devrait être dans un fichier template

Bj

dans package , crée un fichier presence.yaml
et met ceci dedans.

sensor:

  - platform: template 
    sensors:

      presence_domicile:
        unique_id: presence_domicile_tracker
        friendly_name: " Présence Domicile Tracker "
        value_template: >-
          {{is_state('device_tracker.phone_XXXX', 'home') or is_state('device_tracker.XXXXX', 'home')}}

      presence_domicile_wifi:
        unique_id: presence_domicile_wifi
        friendly_name: " Présence Domicile Wifi "
        value_template: >-
          {{is_state('device_tracker.XXXX', 'home') or is_state('device_trackerXXXXX', 'home')}}
          
          

      quelqu_un_a_la_maison:
        unique_id: quelqu_un_a_la_maison_tracker
        friendly_name: " Quelqu'un à la maison Tracker "
        value_template: >-
          {{is_state('device_tracker.XXXXX', 'home') or is_state('device_tracker.XXXX', 'home')}}

      quelqu_un_a_la_maison_wifi:
        unique_id: quelqu_un_a_la_maison_wifi
        friendly_name: " Quelqu'un à la maison Wifi "
        value_template: >-
          {{is_state('device_tracker.XXXXX', 'home') or is_state('device_tracker.XXXXX, 'home')}}

j’arrive a rien

sensor:        

- platform: rest
  scan_interval: '00:30:00'
  name: vacances_scolaires
  json_attributes_path: "$.records[0].fields"
  json_attributes:
    - start_date
    - end_date
    - description
  resource_template: |-
    {% set location = 'Limoges' %}
    {% set rows = '1'%}
    {% set aujourdhui = now().strftime('%Y-%m-%d')%}
    {% set dayOfYear =  now().strftime('%j') %}
    {% set year =  now().strftime('%Y') | int %}
    {% set lastYear = year - 1 %}
    {% set nextYear = year + 1 %}
    {% if dayOfYear > '244' %}
    {% set schoolYear = (year | string) + "-" + (nextYear | string) %}
    {%- else -%}
    {% set schoolYear = (lastYear | string) + "-" + (year | string) %}
    {%- endif %}
    https://data.education.gouv.fr/api/records/1.0/search/?dataset=fr-en-calendrier-scolaire&facet=start_date&facet=end_date&rows={{rows}}&refine.location={{location}}&sort=-end_date&q=end_date%3E={{aujourdhui}}
  value_template: |-
    {% set aujourdhui = now().strftime('%Y-%m-%d')%}
    {% for record in value_json.records -%}
    {% if aujourdhui >= record.fields.start_date and aujourdhui <= record.fields.end_date %} 
    {%- if record.fields.description %}{{record.fields.description}} jusqu'au {{ as_timestamp(record.fields.end_date) | timestamp_custom('%d-%m-%Y') }} {% endif %}
    {% else %} 
    {%- if record.fields.end_date > aujourdhui and record.fields.description %} prochaines : {{record.fields.description}} {{ as_timestamp(record.fields.start_date) | timestamp_custom('%d-%m-%Y') }}{% endif %}
    {% endif %}
    {%- endfor %} 

binary_sensor:

  - platform: template
    sensors:
   name: vacances_scolaires_aujourdhui
      unique_id: binary_sensor.vacances_scolaires_aujourdhui
      state: |-
        {% set aujourdhui = now().strftime('%Y-%m-%d')%}
        {% if aujourdhui < states.sensor.vacances_scolaires.attributes["start_date"] or aujourdhui > states.sensor.vacances_scolaires.attributes["end_date"] %}
        false
        {% else %} 
        true
        {% endif %}

  - platform: template 
    sensors:
   name: vacances_scolaires_demain
      unique_id: binary_sensor.vacances_scolaires_demain
      state: |-
        {% set demain = (as_timestamp(now()) + (24*3600)) | timestamp_custom('%Y-%m-%d', True) %}
        {% if demain < states.sensor.vacances_scolaires.attributes["start_date"] or demain > states.sensor.vacances_scolaires.attributes["end_date"] %} 
        false
        {% else %} 
        true
        {% endif %}     	

Il faut te plonger dans les docs

deja la tu as un souci ( en rouge )

et tes sensors tu fait du repeat en vert

je suis dedans depuit un moment

salut tu l’ancien format
voila avec le nouveau format

sensor:        

- platform: rest
  scan_interval: '00:30:00'
  name: vacances_scolaires
  json_attributes_path: "$.records[0].fields"
  json_attributes:
    - start_date
    - end_date
    - description
  resource_template: |-
    {% set location = 'Limoges' %}
    {% set rows = '1'%}
    {% set aujourdhui = now().strftime('%Y-%m-%d')%}
    {% set dayOfYear =  now().strftime('%j') %}
    {% set year =  now().strftime('%Y') | int %}
    {% set lastYear = year - 1 %}
    {% set nextYear = year + 1 %}
    {% if dayOfYear > '244' %}
    {% set schoolYear = (year | string) + "-" + (nextYear | string) %}
    {%- else -%}
    {% set schoolYear = (lastYear | string) + "-" + (year | string) %}
    {%- endif %}
    https://data.education.gouv.fr/api/records/1.0/search/?dataset=fr-en-calendrier-scolaire&facet=start_date&facet=end_date&rows={{rows}}&refine.location={{location}}&sort=-end_date&q=end_date%3E={{aujourdhui}}
  value_template: |-
    {% set aujourdhui = now().strftime('%Y-%m-%d')%}
    {% for record in value_json.records -%}
    {% if aujourdhui >= record.fields.start_date and aujourdhui <= record.fields.end_date %} 
    {%- if record.fields.description %}{{record.fields.description}} jusqu'au {{ as_timestamp(record.fields.end_date) | timestamp_custom('%d-%m-%Y') }} {% endif %}
    {% else %} 
    {%- if record.fields.end_date > aujourdhui and record.fields.description %} prochaines : {{record.fields.description}} {{ as_timestamp(record.fields.start_date) | timestamp_custom('%d-%m-%Y') }}{% endif %}
    {% endif %}
    {%- endfor %} 

template:

  - binary_sensor:
        name: vacances_scolaires_aujourdhui
        unique_id: binary_sensor.vacances_scolaires_aujourdhui
        state: |-
            {% set aujourdhui = now().strftime('%Y-%m-%d')%}
            {% if aujourdhui < states.sensor.vacances_scolaires.attributes["start_date"] or aujourdhui > states.sensor.vacances_scolaires.attributes["end_date"] %}
            false
            {% else %} 
            true
            {% endif %}

  - binary_sensor:
        name: vacances_scolaires_demain
        unique_id: binary_sensor.vacances_scolaires_demain
        state: |-
            {% set demain = (as_timestamp(now()) + (24*3600)) | timestamp_custom('%Y-%m-%d', True) %}
            {% if demain < states.sensor.vacances_scolaires.attributes["start_date"] or demain > states.sensor.vacances_scolaires.attributes["end_date"] %} 
            false
            {% else %} 
            true
            {% endif %}

ton format est toujours pas bon

voici corriger:

sensor:        
  - platform: rest
    scan_interval: '00:30:00'
    name: vacances_scolaires
    json_attributes_path: "$.records[0].fields"
    json_attributes:
      - start_date
      - end_date
      - description
    resource_template: |-
      {% set location = 'Limoges' %}
      {% set rows = '1'%}
      {% set aujourdhui = now().strftime('%Y-%m-%d')%}
      {% set dayOfYear =  now().strftime('%j') %}
      {% set year =  now().strftime('%Y') | int %}
      {% set lastYear = year - 1 %}
      {% set nextYear = year + 1 %}
      {% if dayOfYear > '244' %}
      {% set schoolYear = (year | string) + "-" + (nextYear | string) %}
      {%- else -%}
      {% set schoolYear = (lastYear | string) + "-" + (year | string) %}
      {%- endif %}
      https://data.education.gouv.fr/api/records/1.0/search/?dataset=fr-en-calendrier-scolaire&facet=start_date&facet=end_date&rows={{rows}}&refine.location={{location}}&sort=-end_date&q=end_date%3E={{aujourdhui}}
    value_template: |-
      {% set aujourdhui = now().strftime('%Y-%m-%d')%}
      {% for record in value_json.records -%}
      {% if aujourdhui >= record.fields.start_date and aujourdhui <= record.fields.end_date %} 
      {%- if record.fields.description %}{{record.fields.description}} jusqu'au {{ as_timestamp(record.fields.end_date) | timestamp_custom('%d-%m-%Y') }} {% endif %}
      {% else %} 
      {%- if record.fields.end_date > aujourdhui and record.fields.description %} prochaines : {{record.fields.description}} {{ as_timestamp(record.fields.start_date) | timestamp_custom('%d-%m-%Y') }}{% endif %}
      {% endif %}
      {%- endfor %}

binary_sensor:
  - plateforme: template
    sensors:
      vacances_scolaires_demain
      unique_id: binary_sensor.vacances_scolaires_demain
      state: |-
      {% set demain = (as_timestamp(now()) + (24*3600)) | timestamp_custom('%Y-%m-%d', True) %}
      {% if demain < states.sensor.vacances_scolaires.attributes["start_date"] or demain > states.sensor.vacances_scolaires.attributes["end_date"] %} 
      false
      {% else %} 
      true
      {% endif %}

@barto_95 regarde la Template - Home Assistant et la


aussi

1 « J'aime »

Autant utiliser le nouveau format, pour être tranquille dans le futur. Car un jour ou l’autre l’ancien format sera supprimer et faudra refaire tout les templates.

1 « J'aime »

@titof2375
@barto_95 te parle de ton indentation encore il y a un décalage il faut faire plus qu’attention les 3/4 du temps quand cela ne fonctionne pas c’est ça

Salut @jerome6994 @barto_95 ne me parlé pas du tous du décalage, il me parlé de sensor du début du code qu’il fallait que je les passe en template, mes ça me mes des erreurs en permanence.