Home Assistant är ett populärt program för att styra smarta hem, och det är flera som har frågat om hur man kan få in data från LargenTemp i Home Assistant. Nedan följer en guide som visar hur du åstadkommer detta med LargenTemp's öppna API.
Inhämtningen av data för Home Assistant görs via Node:Red som är en plattform för att grafiskt skapa flöden och som finns tillgänglig för Home Assistant. Det är dock inte installerat som standard och måste därför installeras innan du kan använda koden nedan (om du inte redan har det installerat). Börja med att installera Node:Red-tillägget till Home Assistant som du kan hitta mer info om här (en guide för hur du installerar tillägg i Home Assistant kan du hitta här). Du måste också installera Node-RED Companion som kräver att du har Home Assistant Community Store ("HACS") installerat. Om du inte har det så kan du läsa mer om hur du laddar ner det här eller följa en videoguide istället här. Om du inte har installerat "HACS" tidigare, glöm inte att göra en backup innan du börjar!
Se till att du har installerat tillägget Node-RED Companion innan du börjar!
Öppna först Node:Red, vilket du kan göra genom att hitta tillägget i Home Assistant och välja "Öppna webbgränsnitt".
När du väl har Node:Red öppnat så är det inte svårare att att kopiera och klistra in saker! Börja med att kopiera koden nedan:
[{"id":"7920485f.391408","type":"tab","label":"LargenTemp","disabled":false,"info":""},{"id":"deea7c92.667868","type":"inject","z":"7920485f.391408","name":"Var 7:e minut","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"420","crontab":"","once":true,"onceDelay":"3","topic":"","payload":"","payloadType":"date","x":120,"y":120,"wires":[["c7e357c2.fde1e"]]},{"id":"c7e357c2.fde1e","type":"http request","z":"7920485f.391408","name":"Hämta data från LargenTemp","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://largentemp.pythonanywhere.com/openapi","tls":"451e33e8.f087cc","persist":false,"proxy":"","authType":"","x":290,"y":200,"wires":[["493a411c.25a27","1c33cf59.037221"]]},{"id":"745e9343.6617dc","type":"ha-entity","z":"7920485f.391408","name":"Ställ in temperatur som en sensor","server":"74572ba.4f2cdd4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Largen-temperatur"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:waves"},{"property":"unit_of_measurement","value":"C"}],"state":"payload.temperaturedata","stateType":"msg","attributes":[{"property":"id","value":"largentemp_temperature","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":620,"y":360,"wires":[[]]},{"id":"493a411c.25a27","type":"debug","z":"7920485f.391408","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":200,"wires":[]},{"id":"1c33cf59.037221","type":"function","z":"7920485f.391408","name":"Konvertera data","func":"/* Konverterar data till formatet JSON för fortsatt användning i koden. */\nmsg.payload = JSON.parse(msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":280,"wires":[["745e9343.6617dc","6d956a18.4bdc34","995b22c4.e486c","b4277539.5deee","c8dfc2dc.cdcb9","3a173570.c436fa","adcae940.ec962","b5f66c7e.7df2d8"]]},{"id":"6d956a18.4bdc34","type":"ha-entity","z":"7920485f.391408","name":"Ställ in uppdateringstid som en sensor","server":"74572ba.4f2cdd4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Largen-temperatur senast uppdaterad"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:calendar"},{"property":"unit_of_measurement","value":""}],"state":"payload.latestupdated.string","stateType":"msg","attributes":[{"property":"id","value":"largentemp_temperature_updated","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":630,"y":420,"wires":[[]]},{"id":"995b22c4.e486c","type":"ha-entity","z":"7920485f.391408","name":"Ställ in högsta uppmätta värde idag som en sensor","server":"74572ba.4f2cdd4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Högsta temperatur i Largen idag"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:thermometer-high"},{"property":"unit_of_measurement","value":"C"}],"state":"payload.statistics.today_high","stateType":"msg","attributes":[{"property":"id","value":"highest_largentemp_temperature_today","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":670,"y":480,"wires":[[]]},{"id":"b4277539.5deee","type":"ha-entity","z":"7920485f.391408","name":"Ställ in lägsta uppmätta värde idag som en sensor","server":"74572ba.4f2cdd4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Lägsta temperatur i Largen idag"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:thermometer-low"},{"property":"unit_of_measurement","value":"C"}],"state":"payload.statistics.today_low","stateType":"msg","attributes":[{"property":"id","value":"lowest_largentemp_temperature_today","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":670,"y":540,"wires":[[]]},{"id":"c8dfc2dc.cdcb9","type":"ha-entity","z":"7920485f.391408","name":"Ställ in medelvärde idag som en sensor","server":"74572ba.4f2cdd4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Medeltemperatur i Largen idag"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:chart-line-variant"},{"property":"unit_of_measurement","value":"C"}],"state":"payload.statistics.today_mean","stateType":"msg","attributes":[{"property":"id","value":"mean_largentemp_temperature_today","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":640,"y":600,"wires":[[]]},{"id":"3a173570.c436fa","type":"ha-entity","z":"7920485f.391408","name":"Ställ in antal värden rapporterade idag som en sensor","server":"74572ba.4f2cdd4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Inrapporterade temperaturvärden för Largen idag"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:information"},{"property":"unit_of_measurement","value":""}],"state":"payload.statistics.value_count_today","stateType":"msg","attributes":[{"property":"id","value":"largentemp_temperature_values_reported_today","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":680,"y":720,"wires":[[]]},{"id":"adcae940.ec962","type":"ha-entity","z":"7920485f.391408","name":"Ställ in medianvärde idag som en sensor","server":"74572ba.4f2cdd4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Mediantemperatur i Largen idag"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:chart-line-variant"},{"property":"unit_of_measurement","value":"C"}],"state":"payload.statistics.today_median","stateType":"msg","attributes":[{"property":"id","value":"median_largentemp_temperature_today","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":640,"y":660,"wires":[[]]},{"id":"8cf5aa6b.12493","type":"ha-entity","z":"7920485f.391408","name":"Ställ in om temperaturdata finns tillgängligt idag som en sensor","server":"74572ba.4f2cdd4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Temperaturdata för Largen från idag tillgängligt"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[{"property":"id","value":"largentemp_temperature_values_for_today_available","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":1010,"y":880,"wires":[[]]},{"id":"b5f66c7e.7df2d8","type":"function","z":"7920485f.391408","name":"Kontrollera om temperaturdata finns tillgänglig idag","func":"/* Kontrollerar baserat på API-svar om temperaturdatan\nför idag har uppdaterats eller inte. */\nif (msg.payload.statistics.value_count_today > 0){\n msg.payload = \"on\";\n}\nelse {\n msg.payload = \"off\";\n}\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":670,"y":780,"wires":[["8cf5aa6b.12493"]]},{"id":"451e33e8.f087cc","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":true},{"id":"74572ba.4f2cdd4","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
Koden finns också som en nedladdningsbar länk här.
I Node:Red så trycker du på de tre vertikala strecken längst upp i hörnet.
Sedan trycker du på "Import". Det borde komma upp en ruta som säger något i stil med "Paste flow json".
Nu kopierar du bara in all kod som du hittar ovan och klickar på "Import".
Klicka på "Deploy"-knappen längst upp i högra hörnet. Nu borde du ha flera entiteter i Home Assistant med data:
Som standard uppdaterar flödet du nyss importerade i Node:Red data automatiskt var sjunde minut, vilket är så ofta ny data kommer in på LargenTemp. Det är bara att luta dig tillbaka! Om du använder datan till något kul i Home Assistant vill vi jättegärna veta hur! Skicka gärna ett mail och berätta.