#Déclaration des sensors pour le WES
  - platform: rest
    name: wesdata
#Remplacer par IP de votre WES
    resource: http://IP_DU_WES/data.cgx
    scan_interval: 60
    method: GET
    authentication: basic
#Remplacer par le nom utilisateur et mot de passe de votre systeme
    username: admin
    password: wes
    json_attributes_path: "$.data"
    json_attributes:
      - "tic1"
      - "tic2"
      - "tic3"
      - "impulsion"
      - "pince"
      - "temp"
      - "relais"
      - "entree"
      - "analogique"
      - "switch_virtuel"
      - "variables"
    value_template: 'OK'
  - platform: template
    sensors:
# Capteur pour déterminer si on est en heures creuses    
        westic1tarif :
          friendly_name: "Tarif en cours"
          unique_id: westic1tarif
          value_template: >-
           {{ states.sensor.wesdata.attributes["tic1"]["PTEC"] }}
        wesheurecreuse :
          friendly_name: "Heures Creuses"
          unique_id: wesheurecreuse
          value_template: >-
            {% if "creuse" in states.sensor.wesdata.attributes["tic1"]["PTEC"].lower() %}
                1
            {% else %}
                0
            {% endif %}

#Si abonnement de base
#       westic1base :
#        friendly_name: "Index Base Electricité"
#        unique_id: westic1base
#        device_class : energy
#        unit_of_measurement: 'Wh'
#        value_template: >-
#            {{ states.sensor.wesdata.attributes["tic1"]["BASE"]| float }}

#Si abonnement heures pleines heures creuses
#       westic1hp :
#        friendly_name: "Index Heures Pleines"
#        unique_id: westic1hp
#        device_class : energy
#        unit_of_measurement: 'Wh'
#        value_template: >-
#            {{ states.sensor.wesdata.attributes["tic1"]["H_PLEINE"]| float }}
#       westic1hc :
#        friendly_name: "Index Heures Creuses"
#        unique_id: westic1hc
#        device_class : energy
#        unit_of_measurement: 'Wh'
#        value_template: >-
#            {{ states.sensor.wesdata.attributes["tic1"]["H_CREUSE"]| float }}        

#Si abonnement Tempo
        westic1bleuhp :
          friendly_name: "Index Heures Pleines Bleu"
          unique_id: westic1bleuhp
          device_class : energy
          unit_of_measurement: 'Wh'
          value_template: >-
           {{ states.sensor.wesdata.attributes["tic1"]["BBRHPJB"] | float  }}
           
        westic1bleuhc :
          friendly_name: "Index Heures Creuses Bleu"
          unique_id: westic1bleuhc
          device_class : energy
          unit_of_measurement: 'Wh'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic1"]["BBRHCJB"]| float }}
        westic1blanchp :
          friendly_name: "Index Heures Pleines Blanc"
          unique_id: westic1blanchp
          device_class : energy
          unit_of_measurement: 'Wh'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic1"]["BBRHPJW"] | float  }}
        westic1blanchc :
          friendly_name: "Index Heures Creuses Blanc"
          unique_id: westic1blanchc
          device_class : energy
          unit_of_measurement: 'Wh'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic1"]["BBRHCJW"]| float }}
        westic1rougehp :
          friendly_name: "Index Heures Pleines Rouge"
          unique_id: westic1rougehp
          device_class : energy
          unit_of_measurement: 'Wh'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic1"]["BBRHPJR"] | float  }}
        westic1rougehc :
          friendly_name: "Index Heures Creuses Rouge"
          unique_id: westic1rougehc
          device_class : energy
          unit_of_measurement: 'Wh'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic1"]["BBRHCJR"]| float }}
        westic1inj :
          friendly_name: "Index Injection"
          unique_id: westic1inj
          device_class : energy
          unit_of_measurement: 'Wh'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic1"]["INJECTION"]| float }}
      
        westic1pap :
          friendly_name: "Consommation Instantanée"
          unique_id: westic1pap
          device_class : apparent_power
          unit_of_measurement: 'VA'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic1"]["PAP"]| float }}
        westic1tension :
          friendly_name: "Tension Consommation"
          unique_id: westic1tension
          device_class : power
          unit_of_measurement: 'V'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic1"]["TENSION1"]| float }}  
             
#Second compteur TIC utilisé ici pour la production photovoltaique
        westic2prod :
          friendly_name: "Index Production"
          unique_id: westic2prod
          device_class : energy
          unit_of_measurement: 'Wh'
          value_template: >-
              {{ states.sensor.wesdata.attributes["tic2"]["PRODUCTEUR"]| float }}
        westic2pap :
          friendly_name: "Consommation Instantanée"
          unique_id: westic2pap
          device_class : apparent_power
          unit_of_measurement: 'VA'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic2"]["PAP"]| float }}              
        westic2tension :
          friendly_name: "Tension Production"
          unique_id: westic2tension
          device_class : power
          unit_of_measurement: 'V'
          value_template: >-
               {{ states.sensor.wesdata.attributes["tic2"]["TENSION1"]| float }}        
          
#Capteurs impulsion, utilisés par exemple pour eau ou gaz
        wesimpulsion1 :
          friendly_name: "Compteur Eau"
          unique_id: wesimpulsion1
          device_class : water
          unit_of_measurement: 'L'
          value_template: >-
              {{ states.sensor.wesdata.attributes["impulsion"]["INDEX1"]| float }} 
#       wesimpulsion2 :
#        friendly_name: "Compteur Gaz"
#        unique_id: wesimpulsion2
#        device_class : gas
#        unit_of_measurement: 'm3'
#        value_template: >-
#            {{ states.sensor.wesdata.attributes["impulsion"]["INDEX2"]| float }}
#       wesimpulsion3 :
#        friendly_name: "Compteur Autre"
#        unique_id: wesimpulsion3
#        device_class : water
#        unit_of_measurement: 'l'
#        value_template: >-
#            {{ states.sensor.wesdata.attributes["impulsion"]["INDEX3"]| float }}

#Pinces ampere metriques pour suivre certains postes spécifiques
        wespince1inst :
          friendly_name: "Chauffe Eau Instantané"
          unique_id: wespince1inst
          device_class : current
          unit_of_measurement: 'A'
          value_template: >-
               {{ states.sensor.wesdata.attributes["pince"]["I1"]| float }}
        wespince1total :
          friendly_name: "Chauffe Eau Total"
          unique_id: wespince1total
          device_class : energy
          unit_of_measurement: 'kWh'
          value_template: >-
               {{ states.sensor.wesdata.attributes["pince"]["INDEX1"]| float }}
        wespince1watt:
          friendly_name: "Consommation Chauffe Eau"
          unique_id: wespince1watt
          device_class : power
          unit_of_measurement: 'W'
          value_template: >-
            {{ (states.sensor.wesdata.attributes["tic1"]["TENSION1"] | float) * (states.sensor.wesdata.attributes["pince"]["I1"] | float) }}
        wespince2inst :
          friendly_name: "Chauffage Instantané"
          unique_id: wespince2inst
          device_class : current
          unit_of_measurement: 'A'
          value_template: >-
              {{ states.sensor.wesdata.attributes["pince"]["I2"]| float }}
        wespince2total :
          friendly_name: "Chauffage Total"
          unique_id: wespince2total
          device_class : energy
          unit_of_measurement: 'kWh'
          value_template: >-
              {{ states.sensor.wesdata.attributes["pince"]["INDEX2"]| float }}
        wespince2watt:
          friendly_name: "Consommation Chauffage"
          unique_id: wespince2watt
          device_class : power
          unit_of_measurement: 'W'
          value_template: >-
            {{ (states.sensor.wesdata.attributes["tic1"]["TENSION1"] | float) * (states.sensor.wesdata.attributes["pince"]["I2"] | float) }}
        wespince3inst :
          friendly_name: "Autres prises Instantané"
          unique_id: wespince3inst
          device_class : current
          unit_of_measurement: 'A'
          value_template: >-
             {{ states.sensor.wesdata.attributes["pince"]["I3"]| float }}
        wespince3total :
          friendly_name: "Autres prises Total"
          unique_id: wespince3total
          device_class : energy
          unit_of_measurement: 'kWh'
          value_template: >-
              {{ states.sensor.wesdata.attributes["pince"]["INDEX3"]| float }}
        wespince3watt:
          friendly_name: "Consommation Autres prises"
          unique_id: wespince3watt
          device_class : power
          unit_of_measurement: 'W'
          value_template: >-
            {{ (states.sensor.wesdata.attributes["tic1"]["TENSION1"] | float) * (states.sensor.wesdata.attributes["pince"]["I3"] | float) }}
        wespince4inst :
          friendly_name: "Gros Electroménager Instantané"
          unique_id: wespince4inst
          device_class : current
          unit_of_measurement: 'A'
          value_template: >-
              {{ states.sensor.wesdata.attributes["pince"]["I4"]| float }}
        wespince4total :
          friendly_name: "Gros Electroménager Total"
          unique_id: wespince4total
          device_class : energy
          unit_of_measurement: 'kWh'
          value_template: >-
              {{ states.sensor.wesdata.attributes["pince"]["INDEX4"]| float }}
        wespince4watt:
          friendly_name: "Consommation Gros Electroménager"
          unique_id: wespince4watt
          device_class : power
          unit_of_measurement: 'W'
          value_template: >-
            {{ (states.sensor.wesdata.attributes["tic1"]["TENSION1"] | float) * (states.sensor.wesdata.attributes["pince"]["I4"] | float) }}
       
#Sondes de température, possible jusqu'à 30
#        wessonde1 :
#          friendly_name: "Salon"
#          unique_id: wessonde1
#          device_class : temperature
#          unit_of_measurement: '°C'
#          value_template: >-
#             {{ states.sensor.wesdata.attributes["temp"]["SONDE1"]| float }} 
#        wessonde2 :
#          friendly_name: "Chambre"
#          unique_id: wessonde2
#          device_class : temperature
#          unit_of_measurement: '°C'
#          value_template: >-
#             {{ states.sensor.wesdata.attributes["temp"]["SONDE2"]| float }}  
#        wessonde3 :
#          friendly_name: "Salle de Bain"
#          unique_id: wessonde3
#          device_class : temperature
#          unit_of_measurement: '°C'
#          value_template: >-
#              {{ states.sensor.wesdata.attributes["temp"]["SONDE3"]| float }}   

#Relais
#       wesrelai1 :
#        friendly_name: "Relai 1"
#        unique_id: wesrelai1
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["relais"]["RELAIS1"]| float }}  
#       wesrelai2 :
#        friendly_name: "Relai 2"
#        unique_id: wesrelai2
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["relais"]["RELAIS2"]| float }}           
 
#Entrees
#       wesentree1 :
#        friendly_name: "Entrée 1"
#        unique_id: wesentree1
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["entree"]["ENTREE1"]| float }}  
#       wesentree2 :
#        friendly_name: "Entrée 2"
#        unique_id: wesentree2
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["entree"]["ENTREE2"]| float }}     
       
#Analogique possible jusqu'à 4
#       wesanalogique1 :
#        friendly_name: "Analogique 1"
#        unique_id: wesanalogique1
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["analogique"]["AD1"]| float }}  
#       wesanalogique2 :
#        friendly_name: "Analogique 2"
#        unique_id: wesanalogique2
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["analogique"]["AD2"]| float }}   

#Switch Virtuels, jusque 24
#       wesswtich1 :
#        friendly_name: "Switch 1"
#        unique_id: wesswtich1
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["switch_virtuel"]["SWITCH1"]| float }}  
#       wesswtich2 :
#        friendly_name: "Switch 2"
#        unique_id: wesswtich2
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["switch_virtuel"]["SWITCH2"]| float }}   

#Variables, jusqu'à 8
#       wesvariable1 :
#        friendly_name: "Gros Electroménager Total"
#        unique_id: wesvariable1
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["variables"]["VARIABLE1"]| float }}  
#       wesvariable2 :
#        friendly_name: "Gros Electroménager Total"
#        unique_id: wesvariable2
#        value_template: >-
#             {{ states.sensor.wesdata.attributes["variables"]["VARIABLE2"]| float }}   
 