Sensor - Monitorar o preço médio da Gasolina na sua cidade

Aqui, amigo, um nó que tem o reinício do HA como trigger:

[{"id":"7441790d2fd4a367","type":"tab","label":"HA","disabled":false,"info":"","env":[]},{"id":"6a353729f4cfbff8","type":"server-events","z":"7441790d2fd4a367","name":"Trigger: Iniciação do HA","server":"8f275663.76e378","version":1,"event_type":"home_assistant_client","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"event_type","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":360,"y":80,"wires":[[]]},{"id":"8f275663.76e378","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

2 curtidas

Boa tarde amigo, vc conseguiu pegar de um posto específico? Se sim, como fez?

Consegui fazendo um pequeno ajuste no nó seletor. Ve se te ajuda:

[{"id":"5255af6d8e388b78","type":"inject","z":"d3aa8e69.760e3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"43200","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":174.0000343322754,"y":944.0000410079956,"wires":[["25099b34021eb308"]]},{"id":"25099b34021eb308","type":"http request","z":"d3aa8e69.760e3","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://precodoscombustiveis.com.br/pt-br/station/brasil/rio-de-janeiro/itaborai/district/posto-amigao/3858","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"credentials":{"user":"","password":""},"x":414.0000343322754,"y":944.0000410079956,"wires":[["6cd3c8867de86bfd"]]},{"id":"6cd3c8867de86bfd","type":"html","z":"d3aa8e69.760e3","name":"Selector","property":"payload","outproperty":"payload","tag":"#Gasstation > div.row.py-5 > div.col-xl-3.p-5.p-md-3 > div:nth-child(2) > div > span:nth-child(5)","ret":"html","as":"single","x":584.0000343322754,"y":944.0000410079956,"wires":[["34c092bb460aa609"]]},{"id":"34c092bb460aa609","type":"function","z":"d3aa8e69.760e3","name":"","func":"msg.payload = parseFloat(msg.payload[0].replace('R$ ',''))\n\nmsg.entity_id = 'sensor.gasolina_media_amigao'\n\nmsg.payload = {\n    data: {\n        state: msg.payload,\n        attributes: {\n            friendly_name: 'gasolina_media_amigao',\n            unit_of_measurement: 'R$'\n        }\n    }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":764.0000343322754,"y":944.0000410079956,"wires":[["030c87e2166d4860"]]},{"id":"030c87e2166d4860","type":"ha-api","z":"d3aa8e69.760e3","name":"","server":"b771286b.8c8f28","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"/api/states/{{entity_id}}","data":"","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":934.0000343322754,"y":944.0000410079956,"wires":[["a703abb769f994e1"]]},{"id":"0b2860e8b983e6db","type":"telegrambot-notify","z":"d3aa8e69.760e3","name":"","bot":"f783de8c8a9692c3","chatId":"1535233309","message":"Valores da gasolina <b>Posto Amigão (Duques)</b> atualizado","parseMode":"HTML","x":1304.0000343322754,"y":944.0000410079956,"wires":[]},{"id":"a703abb769f994e1","type":"delay","z":"d3aa8e69.760e3","name":"Lim 1 msg por H","pauseType":"rate","timeout":"15","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"hour","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":1104.0000343322754,"y":944.0000410079956,"wires":[["0b2860e8b983e6db"]]},{"id":"b771286b.8c8f28","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"},{"id":"f783de8c8a9692c3","type":"telegrambot-config","botname":"Neuber_bot","usernames":"","chatIds":"","pollInterval":"300"}]
1 curtida

Como ficou? tentei aqui e não consegui… :frowning:

Esse ajudou bastante, parabéns!!!

1 curtida

@IceDragon , por favor, poderia me ajudar a configurar o nó seletor para esse posto especifico ?

Agradeço se compartilhar o procedimento para editar esse nó seletor, assim podemos fazer para outros postos.
Muito obrigado !

1 curtida

Claro, sem problema.
Eu fiz esse nó de forma que é só alterar a url, no nó http-request, para o posto do seu interesse. O resultado te dá o valor da gasolina, com os valores em R$ já com 2 casas decimais.

[{"id":"50710bd3ae852690","type":"inject","z":"13a11bc58fb374e4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1320,"y":4700,"wires":[["ef80042b46e1b17d"]]},{"id":"ef80042b46e1b17d","type":"http request","z":"13a11bc58fb374e4","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://precodoscombustiveis.com.br/pt-br/station/brasil/sao-paulo/santo-andre/district/posto-carrefour/15743","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":1470,"y":4700,"wires":[["26d2c0396aa9404b","19bd7b1f28ab9d60"]]},{"id":"26d2c0396aa9404b","type":"html","z":"13a11bc58fb374e4","name":"Selector","property":"payload","outproperty":"payload","tag":"#Gasstation > div.row.py-5 > div.offset-xl-1.col-xl-7.col-12.p-5.p-md-0 > div:nth-child(2) > div:nth-child(1) > div > div > div > div > span.price","ret":"html","as":"single","x":1620,"y":4700,"wires":[["7fc90e51c1484e23"]]},{"id":"19bd7b1f28ab9d60","type":"html","z":"13a11bc58fb374e4","name":"Date","property":"payload","outproperty":"payload","tag":"#Gasstation > div.row.py-5 > div.offset-xl-1.col-xl-7.col-12.p-5.p-md-0 > div:nth-child(2) > div:nth-child(1) > div > div > div > div > span:nth-child(3)","ret":"text","as":"single","x":1610,"y":4760,"wires":[["280e22cdd8a2e70e"]]},{"id":"280e22cdd8a2e70e","type":"change","z":"13a11bc58fb374e4","name":"updated at","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1770,"y":4760,"wires":[["8ee7d850c6c52437"]]},{"id":"7fc90e51c1484e23","type":"template","z":"13a11bc58fb374e4","name":"nome do posto","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Posto Carrefour","output":"str","x":1780,"y":4700,"wires":[["deef933ed9c2fe9b"]]},{"id":"8ee7d850c6c52437","type":"delay","z":"13a11bc58fb374e4","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1930,"y":4760,"wires":[["67f6f475c7e93c76"]]},{"id":"deef933ed9c2fe9b","type":"function","z":"13a11bc58fb374e4","name":"Função","func":"topic = msg.topic\nvalue = msg.payload[0]\n\nvalue = value.replace('R$ ', '')\n\nvalue = Math.round(value * 100) / 100\n\nvalue = value.toString().replace('.', ',')\n\nmsg.payload = topic + ': R$' + value\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1940,"y":4700,"wires":[["67f6f475c7e93c76"]]},{"id":"67f6f475c7e93c76","type":"join","z":"13a11bc58fb374e4","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":", atualizado ","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":2110,"y":4700,"wires":[["2ba7995370e7a992"]]},{"id":"2ba7995370e7a992","type":"debug","z":"13a11bc58fb374e4","name":"Valor da gasolina","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2270,"y":4700,"wires":[]},{"id":"e15aa844a32934ca","type":"comment","z":"13a11bc58fb374e4","name":"Basta alterar o nó http request para a página do posto","info":"","x":1440,"y":4640,"wires":[]}]

image

Testa aí e me diz se deu certo!

1 curtida

@IceDragon, deu certo sim ! Muito Obrigado !

1 curtida

O waze poderia disponibilizar né? Acredito que seja mais atualizado…

Boa tarde ! Estou utilizando essa integração direcionada diretamente ao site da ANP.gov. “Todos valores atualizados” e um range grande de postos de gasolina por cidade.

https://preco.anp.gov.br/include/Resumo_Semanal_Index.asp

2 curtidas

Muito legal.
da pra fazer um card onde indica se é melhor abastecer com gasolina ou álcool ?

É possível sim Após criar todas as entidades, faça a seleção de valor pelo FUNCTION e pode mandar o payload com os dados para Telegram, ZAP, Alexa, etc…

Ainda está funcionando esse?

Testei aqui e da erro:

25/06/2022 00:31:50node: ef80042b46e1b17dmsg : error

“RequestError: getaddrinfo ENOTFOUND precodoscombustiveis.com.br”

25/06/2022 00:31:50node: Funçãofunction : (error)

“TypeError: Cannot read properties of undefined (reading ‘replace’)”

25/06/2022 00:31:51node: Valor da gasolinamsg.payload : string[0]

Não tenho ideia do que se trata. Manda um print do erro.

O meus valores de Curitiba deram ruim no site, ficaram zerados :confused:
vou ver se acho outro lugar para pegar haha

image