Le taf de max5692 est vraiment OK mais n’a pas des maj intra-day car la source prixCarburantClient est configuré pour déclencher une fois (telecharger/unzip/load) et utilise un autre fichier que ma version (instantané).
De base les entity cherchent ses maj individuels et chaque entity déclenche le même processus…avec 16 stations, 16 tele/unzip/load.
J’ai fait quelques améliorations pour télecharger/unzip qu’une fois, si le fichier est moins de 10 min.
Mais, le fichier reste assez grand 890kb et trouver les stations proches est repété pour chaque entity.
Net… est-ce que c’est un processus efficient? … Ca va. chez moi les maj roulent chaque 3600s et c’est déjà trops car mes stations ne recoivent plus des maj après 11:30, alors chaque 2 ou 3 heure est suffisant je pense (à confgurer dans le sensor).
Rien t’empêche de le tenter
@vingerha et @WarC0zes On est bien d’accord que ça n’a rien à voir avec le scrapping… C’est pas plus à mettre dans l’autre sujet tout ça ?
Merci pour ce travail, tout est ok pour moi
J’aimerais y ajouter des graphiques APEXCHART mais je bloque
J’ai déjà un joli graphique pour la conso EDF que je souhaite adapter
L’idée c’est d’avoir une évolution du prix sur la semaine pour le gasoil par exemple
- type: custom:apexcharts-card
card_mod:
style: |
ha-card {
--ha-card-background: rgba(0, 0, 0, 0.1);
color_list:
- deepskyblue
graph_span: 7d
span:
start: day
offset: '-7d'
header:
show: true
title: Suivi Consommation
show_states: false
series:
- entity: sensor.enedisgateway_
type: column
group_by:
duration: 1d
func: max
extend_to_end: false
opacity: 0.8
stroke_width: 4
show:
datalabels: true
data_generator: |
return entity.attributes.dailyweek.map((dailyweek, index) => {
return [new Date(dailyweek).getTime(), entity.attributes.daily[index]];
});
apex_config:
xaxis:
labels:
show: true
yaxis:
labels:
show: true
En changeant l’entité, il ne se passe rien, j’imagine qu’il faut aussi adapter le code « data_generator » ?
Merci pour le tuyau, Je ne savais pas quoi mettre quand les infos est au format div:nth-of-type(3) h1
.
J’ai du modifier mes stations car y a eu une maj au niveau des carburants, et plus rien correspondais
Petit message pour vous remercier tous.
J’ai fait un petit tableau e10 avec les stations de mon coin comme celui de Herbs.
Tout est nickel
Hello
Tu peux partager ton code avec les stations ? Et si possible la belle image de pompes
Merci d’avance
Philippe
Salut @Pbranly
Voici le code multiscrape pour récupérer les infos depuis le site web :
multiscrape:
- name: carburants_feillens
resource: "https://carbu.com/france/index.php/station/intermarche/feillens/01570/16195"
scan_interval: 3600
sensor:
- unique_id: carburants_feillens
select: "[itemtype='http://data-vocabulary.org/Organization'] h1"
value_template: "{{ value }}"
attributes:
- name: sp98_name
select: ".col-xs-12:nth-of-type(1) h2"
- name: sp98_price
select: ".col-xs-12:nth-of-type(1) h1.price"
value_template: "{{ value|replace(',','.') }}"
- name: sp98_date
select: ".col-xs-12:nth-of-type(1) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: sp95_e10_name
select: ".col-xs-12:nth-of-type(3) h2.title"
- name: sp95_e10_price
select: ".col-xs-12:nth-of-type(3) h1"
value_template: "{{ value|replace(',','.') }}"
- name: sp95_e10_date
select: ".col-xs-12:nth-of-type(3) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: bio_e85_name
select: ".col-xs-12:nth-of-type(4) h2"
- name: bio_e85_price
select: ".col-xs-12:nth-of-type(4) h1"
value_template: "{{ value|replace(',','.') }}"
- name: bio_e85_date
select: ".col-xs-12:nth-of-type(4) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: diesel_name
select: ".col-xs-12:nth-of-type(5) h2"
- name: diesel_price
select: ".col-xs-12:nth-of-type(5) h1"
value_template: "{{ value|replace(',','.') }}"
- name: diesel_date
select: ".col-xs-12:nth-of-type(5) p"
value_template: "{{ value.split(' ')[0] }}"
- name: carburants_auchan
resource: "https://carbu.com/france/index.php/station/auchan/macon/71000/6438"
scan_interval: 3600
sensor:
- unique_id: carburants_auchan
select: "[itemtype='http://data-vocabulary.org/Organization'] h1"
value_template: "{{ value }}"
attributes:
- name: sp98_name
select: ".col-xs-12:nth-of-type(1) h2"
- name: sp98_price
select: ".col-xs-12:nth-of-type(1) h1.price"
value_template: "{{ value|replace(',','.') }}"
- name: sp98_date
select: ".col-xs-12:nth-of-type(1) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: sp95_e10_name
select: ".col-xs-12:nth-of-type(3) h2"
- name: sp95_e10_price
select: ".col-xs-12:nth-of-type(3) h1.price"
value_template: "{{ value|replace(',','.') }}"
- name: sp95_e10_date
select: ".col-xs-12:nth-of-type(3) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: gpl_name
select: ".col-xs-12:nth-of-type(5) h2"
- name: gpl_price
select: ".col-xs-12:nth-of-type(5) h1"
value_template: "{{ value|replace(',','.') }}"
- name: gpl_date
select: ".col-xs-12:nth-of-type(5) p"
value_template: "{{ value.split(' ')[0] }}"
- name: diesel_name
select: ".col-xs-12:nth-of-type(4) h2"
- name: diesel_price
select: ".col-xs-12:nth-of-type(4) h1"
value_template: "{{ value|replace(',','.') }}"
- name: diesel_date
select: ".col-xs-12:nth-of-type(4) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: carburants_bien
resource: "https://carbu.com/france/index.php/station/atac/saint-benigne/01190/12119"
scan_interval: 3600
sensor:
- unique_id: carburants_bien
select: "[itemtype='http://data-vocabulary.org/Organization'] h1"
value_template: "{{ value }}"
attributes:
- name: sp98_name
select: ".col-xs-12:nth-of-type(1) h2"
- name: sp98_price
select: ".col-xs-12:nth-of-type(1) h1.price"
value_template: "{{ value|replace(',','.') }}"
- name: sp98_date
select: ".col-xs-12:nth-of-type(1) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: sp95_e10_name
select: ".col-xs-12:nth-of-type(2) h2"
- name: sp95_e10_price
select: ".col-xs-12:nth-of-type(2) h1"
value_template: "{{ value|replace(',','.') }}"
- name: sp95_e10_date
select: ".col-xs-12:nth-of-type(2) p"
value_template: "{{ value.split(' ')[0] }}"
- name: diesel_name
select: ".col-xs-12:nth-of-type(4) h2"
- name: diesel_price
select: ".col-xs-12:nth-of-type(4) h1"
value_template: "{{ value|replace(',','.') }}"
- name: diesel_date
select: ".col-xs-12:nth-of-type(4) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: carburants_replonges
resource: "https://carbu.com/france/index.php/station/intermarche/replonges/01750/12321"
scan_interval: 3600
sensor:
- unique_id: carburants_replonges
select: "[itemtype='http://data-vocabulary.org/Organization'] h1"
value_template: "{{ value }}"
attributes:
- name: sp95_e5_name
select: ".col-xs-12:nth-of-type(2) h2"
- name: sp95_e5_price
select: ".col-xs-12:nth-of-type(2) h1"
value_template: "{{ value|replace(',','.') }}"
- name: sp95_e5_date
select: ".col-xs-12:nth-of-type(2) p"
value_template: "{{ value.split(' ')[0] }}"
- name: sp95_e10_name
select: ".col-xs-12:nth-of-type(3) h2.title"
- name: sp95_e10_price
select: ".col-xs-12:nth-of-type(3) h1"
value_template: "{{ value|replace(',','.') }}"
- name: sp95_e10_date
select: ".col-xs-12:nth-of-type(3) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: diesel_name
select: ".col-xs-12:nth-of-type(4) h2"
- name: diesel_price
select: ".col-xs-12:nth-of-type(4) h1"
value_template: "{{ value|replace(',','.') }}"
- name: diesel_date
select: ".col-xs-12:nth-of-type(4) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: carburants_fleurville
resource: "https://carbu.com/france/index.php/station/total-access/fleurville/71260/10173"
scan_interval: 3600
sensor:
- unique_id: carburants_fleureville
select: "[itemtype='http://data-vocabulary.org/Organization'] h1"
value_template: "{{ value }}"
attributes:
- name: sp98_name
select: ".col-xs-12:nth-of-type(1) h2"
- name: sp98_price
select: ".col-xs-12:nth-of-type(1) h1.price"
value_template: "{{ value|replace(',','.') }}"
- name: sp98_date
select: ".col-xs-12:nth-of-type(1) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: sp95_e10_name
select: ".col-xs-12:nth-of-type(3) h2.title"
- name: sp95_e10_price
select: ".col-xs-12:nth-of-type(3) h1"
value_template: "{{ value|replace(',','.') }}"
- name: sp95_e10_date
select: ".col-xs-12:nth-of-type(3) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: bio_e85_name
select: ".col-xs-12:nth-of-type(4) h2"
- name: bio_e85_price
select: ".col-xs-12:nth-of-type(4) h1"
value_template: "{{ value|replace(',','.') }}"
- name: bio_e85_date
select: ".col-xs-12:nth-of-type(4) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: diesel_name
select: ".col-xs-12:nth-of-type(5) h2"
- name: diesel_price
select: ".col-xs-12:nth-of-type(5) h1"
value_template: "{{ value|replace(',','.') }}"
- name: diesel_date
select: ".col-xs-12:nth-of-type(5) p"
value_template: "{{ value.split(' ')[0] }}"
*à modifier suivant ta ville
Voici le code pour la card :
type: custom:vertical-stack-in-card
card_mod:
style: |
ha-card {
--ha-card-background: rgba(0, 0, 0, 0.1);
ha-card {
margin-top: 0em;
}
mode: vertical
cards:
- type: picture-entity
entity: binary_sensor.dalg_nas
image: /local/images/essence.jpg
show_name: true
show_state: false
name: Station Service
tap_action:
action: none
hold_action:
action: none
- type: divider
style:
height: 2px
width: 100%
margin-left: auto
margin-right: auto
background: rgba(255, 255, 255, 0.5)
- type: custom:flex-table-card
sort_by: diesel_price
entities:
include: sensor.carburants*
columns:
- data: state
icon: mdi:gas-station
align: left
- name: Diesel
data: diesel_price
align: center
- name: Update
data: diesel_date
align: center
css:
tbody tr:nth-child(odd): 'background-color: rgba(255, 255, 255, 0.2)'
tbody tr:nth-child(even): 'background-color: rgba(255, 255, 255, 0.1)'
tbody tr:nth-child(1): 'color: #00ff00'
tbody tr:nth-child(5): 'color: #FF0000'
card_mod:
style: |
ha-card {
border-radius: 10px;
padding-bottom: 10px;
background-color: rgba(0, 0, 0, 0.1)
}
:host {
font-size: 13px;
border-radius: 10px;
}
- type: divider
style:
height: 2px
width: 100%
margin-left: auto
margin-right: auto
background: rgba(255, 255, 255, 0.5)
- type: custom:flex-table-card
sort_by: sp95_e10_price
entities:
include: sensor.carburants*
columns:
- data: state
icon: mdi:gas-station
align: left
- name: SP95
data: sp95_e10_price
align: center
- name: Update
data: sp95_e10_date
align: center
css:
tbody tr:nth-child(odd): 'background-color: rgba(255, 255, 255, 0.2)'
tbody tr:nth-child(even): 'background-color: rgba(255, 255, 255, 0.1)'
tbody tr:nth-child(1): 'color: #00ff00'
tbody tr:nth-child(5): 'color: #FF0000'
card_mod:
style: |
ha-card {
border-radius: 10px;
background-color: rgba(0, 0, 0, 0.1)
}
:host {
font-size: 13px;
border-radius: 10px;
}
Et voici l’image de la pompe à copier dans le dossier www/image
Merci beaucoup
quel est l’objet de " ```
entity: binary_sensor.dalg_nas
philippe
C’est une entité bidon juste pour insérer l’image.
Y’a surement moyen de faire « plus propre » mais ça fonctionne très bien comme ça
Si je comprends bien, il faut ajouter chaque station individuelle, manuellement comme sensor? Pas d’automatisme comme code postal ou quoi?
Oui, faut ajouter chaque station de ton choix manuellement en créant un sensor pour chacune.
De mon coté depuis j’ai fait quelques ajustements mineurs dont les images des enseignes
En jouant avec value_template
c’est assez simple
sensor:
- unique_id: carburants_auchan
select: "[itemtype='http://data-vocabulary.org/Organization'] h1"
value_template: "<img src='/local/images/brand/auchan.png' style='height:20px;'> {{ value }}"
Salut Pulpy,
Tu as fait exactement ce que je voulais faire…sauf que mon code ne récupère pas mon image…vois tu quelque chose qui n’irait pas ? Sachant que j’arrive à récupérer l’image pour une autre card que je gardais justement car je la trouvais sympa avec l’image. Cela me permettrait de grouper les 2.
Merci pour ton aide
multiscrape:
- name: carburants_intermarche_lentigny
resource: "https://carbu.com/france/index.php/station/intermarche/lentigny/42155/17043"
scan_interval: 3600
sensor:
- unique_id: carburants_intermarche_lentigny
select: "[itemtype='http://data-vocabulary.org/Organization'] h1"
value_template: "<img src='/local/images/Logo_intermarche2.png' style='height:20px;'> {{ value }}"
name: Intermarché Lentigny
picture: /local/images/Logo_intermarche2.png
attributes:
- name: sp98_name
select: ".col-xs-12:nth-of-type(1) h2"
- name: sp98_price
select: ".col-xs-12:nth-of-type(1) h1.price"
value_template: "{{ value|replace(',','.') }}"
- name: sp98_date
select: ".col-xs-12:nth-of-type(1) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: sp95_name
select: ".col-xs-12:nth-of-type(3) h2"
- name: sp95_price
select: ".col-xs-12:nth-of-type(3) h1.price"
value_template: "{{ value|replace(',','.') }}"
- name: sp95_date
select: ".col-xs-12:nth-of-type(3) p.sources"
value_template: "{{ value.split(' ')[0] }}"
- name: B7_name
select: ".col-xs-12:nth-of-type(6) h2"
- name: B7_price
select: ".col-xs-12:nth-of-type(6) h1.price"
value_template: "{{ value|replace(',','.') }}"
- name: B7_date
select: ".col-xs-12:nth-of-type(6) p.sources"
value_template: "{{ value.split(' ')[0] }}"
et pour la card
type: custom:flex-table-card
sort_by: b7_price
entities:
- entity: sensor.carburants_leclerc_riorges
- entity: sensor.carburants_carrefour_riorges
- entity: sensor.carburants_carrefour_roanne
- entity: sensor.carburants_carrefour_mably
- entity: sensor.carburants_carrefour_le_coteau
- entity: sensor.carburants_intermarche_commelle
- entity: sensor.carburants_intermarche_lentigny
- entity: sensor.carburants_intermarche_riorges
- entity: sensor.carburants_super_u_le_coteau
columns:
- data: name
icon: mdi:gas-station
align: left
- name: Diesel
data: b7_price
align: center
- name: SP95
data: sp95_price
align: center
- name: SP98
data: sp98_price
align: center
- name: Date
data: b7_date
align: center
css:
tbody tr:nth-child(odd): 'background-color: rgba(255, 255, 255, 0.1)'
tbody tr:nth-child(even): 'background-color: rgba(255, 255, 255, 0.2)'
tbody tr:nth-child(1): 'color: #00ff00'
tbody tr:nth-child(9): 'color: #f00020'
card_mod: null
style: |
:host {
font-size: 13px;
border-radius: 10px;
border-style: solid;
border-width: 2px 2px 0px 2px;
border-color: #ffffff;
}
Salut,
C’est assez logique, tu mets l’image+texte dans le champ value_template
(qui correspond à state
dans un template)
Et tu n’utilise pas state
mais le champ name
pour l’affichage
Comme d’habitude, encore merci pour ton aide!
Hello à tous.
Une petite évolution sur la carte issue du multiscraping :
Affichage de tous les mini/maxi par stations, avec possibilité de tri/filtrage des carburants et des stations
Il y a quelques adaptations à faire par rapport à la config initiale :
- ajouter
picture
(sans mise en forme) à l’entité
(extrait du template)
- name: carburants_auchan2
resource: "https://carbu.com/france/index.php/station/auchan/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
scan_interval: 3600
sensor:
- unique_id: carburants_auchan2
select: "[itemtype='http://data-vocabulary.org/Organization'] h1"
value_template: "{{value}}"
picture: "/local/images/brands/auchan.png"
attributes:
[...]
- faire un groupe des stations à afficher. En triant le groupe, on triera l’affichage
group:
carburants:
name: "carburants"
entities:
- sensor.carburants_auchan
- sensor.carburants_auchan2
- sensor.carburants_leclerc
- sensor.carburants_intermarche
- Et remplacer la carte
type: custom:stack-in-card
cards:
- type: markdown
content: >-
{% set items = {0:'e10', 1:'sp98', 2:'gpl'} -%}
{% set prices = namespace(minima=[],maxima=[]) %}
{% for i in range(items|length) -%}
{% set tmp = expand('group.carburants')
|selectattr('attributes.'+items[i]+'_price', 'ne', '-')
|map(attribute='attributes.'+items[i]+'_price')|list -%}
{%- set prices.minima = prices.minima + [min(tmp)] -%}
{%- set prices.maxima = prices.maxima + [max(tmp)] -%}
{% endfor -%}
{% set carburants_entities = expand('group.carburants') | map(attribute='entity_id')|list %}
<table class="red"><thead><tr> <th
colspan="2">Enseigne</th>
{% for j in range(items|length) -%}
{{ '<th>'+items[j]|upper+' €/L</th>' }}
{% endfor -%}
<th>Date</th> </tr></thead><tbody>
{% for carburants_entity in carburants_entities -%}
<tr>
<td><img src="{{state_attr(carburants_entity, 'entity_picture')}}" height="20"></td>
<td>{{states(carburants_entity)}}</td>
{% for k in range(items|length) -%}
{% set price=state_attr(carburants_entity, items[k]+'_price') -%}
<td>
{% if price==prices.minima[k] -%}
{{ '<font color=green>'+price+'</font>' }}
{% elif price==prices.maxima[k] -%}
{{ '<font color=red>'+price+'</font>' }}
{% else -%}
{{price}}
{% endif -%}
</td>
{% endfor -%}
<td>{{ state_attr(carburants_entity, 'e10_date') }}</td>
</tr>
{% endfor -%}
</tr></tbody></table>
- Pour trier / filter les carburants, il suffit d’éditer la liste :
{% set items = {0:'e10', 1:'sp98', 2:'gpl'} -%}
Pour ajouter un carburant il ajouter une position 1. Le nom du carburant doit correspondre au prefixe de e85_name.
{% set items = {0:'e10', 3:'sp98', 2:'gpl', 1:'e85'} -%}
Il me reste une connerie à corriger : avoir une couleur de fond des lignes alternatives pour améliorer la lisibilité
Punaise ça m’a pris un temps fou alors que @Clemalex avait déjà donné la solution sur le forum.
Je hais les CSS !!!
- type: markdown
card_mod:
style:
ha-markdown:
$:
ha-markdown-element: |
tr:nth-of-type(even) {
background-color: #292929 !important;
}
content: >-
{% set items = {1:'e10', 0:'sp98', 2:'gpl'} -%} {% set prices =
namespace(minima=[],maxima=[]) %} {% for i in range(items|length) -%}
{% set tmp = expand('group.carburants')
|selectattr('attributes.'+items[i]+'_price', 'ne', '-')
|map(attribute='attributes.'+items[i]+'_price')|list -%}
{%- set prices.minima = prices.minima + [min(tmp)] -%}
{%- set prices.maxima = prices.maxima + [max(tmp)] -%}
{% endfor -%}
{% set carburants_entities = expand('group.carburants') |
map(attribute='entity_id')|list %} <table><thead><tr> <th
colspan="2">Station</th> {% for j in range(items|length) -%}
{{ '<th>'+items[j]|upper+' €/L</th>' }}
{% endfor -%} <th>Date</th> </tr></thead><tbody>
{% for carburants_entity in carburants_entities -%}
<tr>
<td><img src="{{state_attr(carburants_entity, 'entity_picture')}}" height="20"></td>
<td>{{states(carburants_entity)}}</td>
{% for k in range(items|length) -%}
{% set price=state_attr(carburants_entity, items[k]+'_price') -%}
<td align='center'>
{% if price==prices.minima[k] -%}
{{ '<font color=green>'+price+'</font>' }}
{% elif price==prices.maxima[k] -%}
{{ '<font color=#B90000>'+price+'</font>' }}
{% else -%}
{{price}}
{% endif -%}
</td>
{% endfor -%}
<td>{{ state_attr(carburants_entity, 'e10_date') }}</td>
</tr>
{% endfor -%}
</tr></tbody></table>
Perso, j’enlèverai le nom de l’enseigne.
Le logo suffit non ?..
Salut
Juste avec l’enseigne il faut quand même un moyen de différencier les 2 Auchan.