Gå til innhold
  • Bli medlem
Støtt hjemmeautomasjon.no!

Anbefalte innlegg

Skrevet

Jeg fiklet litt med dette i september. Jeg endte opp med scrape badevann.no, gjennom node-red. Hvis jeg ikke husker helt feil fikk jeg til det samme fra YR. Men det kan også være at jeg ikke fikk det til ettersom jeg brukte badevann.no. Badevann.no leverer temp til YR.

Jeg er ganske langt fra en å være utvikler, så det er sikkert mye dårlig kode og praksis. Men den rapporterte hvertfall noen dager frem til de tok opp sensoren fra vannet. 🙂

 

 

image.thumb.png.a5325d34ec92ae4be42eaf21f4cc793f.png

 

[{"id":"0c39566e81bb8ea4","type":"debug","z":"c57ff172a079b457","name":"","active":false,"console":"false","complete":"false","x":1090,"y":480,"wires":[]},{"id":"7816e081d8cc62cc","type":"http request","z":"c57ff172a079b457","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://badevann.no/sjostrand/index.html","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":330,"y":440,"wires":[["a4e03e5132d659fc","7301681fd3aa1562"]]},{"id":"a4e03e5132d659fc","type":"html","z":"c57ff172a079b457","name":"","property":"payload","outproperty":"payload","tag":".container-maaling>p.temperatur","ret":"text","as":"single","x":635.5,"y":440,"wires":[["e414479b3204989a"]]},{"id":"5bd28de075baf5a8","type":"debug","z":"c57ff172a079b457","name":"","active":false,"console":"false","complete":"false","x":1090,"y":440,"wires":[]},{"id":"e414479b3204989a","type":"function","z":"c57ff172a079b457","name":"function 3","func":"msg.payload = msg.payload[0].trim();\nmsg.payload = msg.payload.replace('°', '');\nmsg.payload = msg.payload.replace(',', '.');\nmsg.payload = parseFloat(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":440,"wires":[["5bd28de075baf5a8","0ea7be013cddfc0a"]]},{"id":"7301681fd3aa1562","type":"html","z":"c57ff172a079b457","name":"","property":"payload","outproperty":"payload","tag":".container-maaling>p.observasjon","ret":"html","as":"single","x":640,"y":480,"wires":[["0c39566e81bb8ea4","e7319214d52a1b23"]]},{"id":"2dca4837390903ca","type":"inject","z":"c57ff172a079b457","name":"make request","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10800","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":160,"y":440,"wires":[["7816e081d8cc62cc"]]},{"id":"e7319214d52a1b23","type":"function","z":"c57ff172a079b457","name":"function 4","func":"let string = msg.payload[0];\nstring = string.replaceAll(\"<br/>\", \" \")\nstring = string.split(' ')\n// convert strings to date\n// time\nconst time = string[2]\n\n//day\nlet day = string[4].replace('.', ' ')\nday = day.split(' ')\nday = day[0]\n\n// month\nlet month = string[4].replace('.', ' ')\nmonth = month.split(' ')\nvar month1 = month[1]\n\nmonth1 = month1.toLowerCase();\nvar months = [\"januar\", \"februar\", \"mars\", \"april\", \"mai\", \"juni\", \"juli\", \"august\", \"september\", \"okotber\", \"november\", \"desember\"];\nmonth1 = months.indexOf(month1) + 1;\nif (month1 < 10){\n    month1 = \"0\" + month1;\n}\n\n// year\nvar year = string[5].replace(',', '');\n\n//formatted date\nvar fulldate = time + \", \" + day + \"-\" + month1 + \"-\" + year;\n\n//messages\nmsg.payload[0] = time;\nmsg.payload[1] = day;\nmsg.payload[2] = month1;\nmsg.payload[3] = year;\nmsg.payload[4] = fulldate;\n\nmsg.unconverted = string;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":520,"wires":[["dd5cf51d5db1e569","89930a5dc84489d4"]]},{"id":"dd5cf51d5db1e569","type":"debug","z":"c57ff172a079b457","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1070,"y":520,"wires":[]},{"id":"89930a5dc84489d4","type":"ha-sensor","z":"c57ff172a079b457","name":"","entityConfig":"a28569d1428149b7","version":0,"state":"payload[4]","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":1070,"y":560,"wires":[[]]},{"id":"0ea7be013cddfc0a","type":"ha-sensor","z":"c57ff172a079b457","name":"temp","entityConfig":"a5f24590b9fa0e64","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":1070,"y":400,"wires":[[]]},{"id":"2e2322c710db25e2","type":"comment","z":"c57ff172a079b457","name":"Get bath temperature","info":"","x":480,"y":360,"wires":[]},{"id":"a28569d1428149b7","type":"ha-entity-config","server":"dc0802f6.645fa","deviceConfig":"8feaeddb449a1627","name":"Sea temperature","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Sea temperature"},{"property":"icon","value":"mdi:swim"},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"a5f24590b9fa0e64","type":"ha-entity-config","server":"dc0802f6.645fa","deviceConfig":"8feaeddb449a1627","name":"Sea temp","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Sea temp"},{"property":"icon","value":"mdi:swim"},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":"temperature"},{"property":"unit_of_measurement","value":"°C"},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"dc0802f6.645fa","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"8feaeddb449a1627","type":"ha-device-config","name":"Sea-temp","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""}]

 

  • Like 2
  • 2 uker senere...
Skrevet (endret)

Ble litt inspirert, og fant ut at YR har et tilgjengelig API for observasjoner. Dette er observasjoner registert av hvem som helst, jeg antar at observasjoner fra feks "badetassen" ikke er tilgjengelig selv om de vises på yr.no.

 

Så jeg laget en sensor for å hente temperatur for et spesifikt sted:

 

1. Send en e-post som beskrevet i APIet til for å få en API-key 🗝️ https://hjelp.yr.no/hc/no/articles/5949243432850

2. Finn ønsket sted https://www.yr.no/nb/badetemperaturer

3. I URL hent ut location ID,  i dette tilfellet: 1-73316. https://www.yr.no/nb/værvarsel/daglig-tabell/1-73316/Norge/Akershus/Asker/Sjøstrand

4. I din secrets.yaml legg til: yr_api_key: din_nøkkel_her

5. Kopier inn kode i configuration.yaml / evt. sensor.yaml:
 

sensor:
  - platform: rest
    resource: "https://badetemperaturer.yr.no/api/locations/1-73316/watertemperatures"
    headers:
      apikey: !secret yr_api_key
    name: "Sjøstrand"
    value_template: "{{ value_json[0]['temperature'] }}"
    device_class: temperature
    json_attributes:
      - time

6. Endre ID i URL i resource

7. Endre name til noe som gir deg mening.

8. Reload YAML 🙂 

 

Også kopierer jeg bare sensoren jeg laget i node-red mens jeg testet APIet:

[{"id":"131349fa60f6bae7","type":"inject","z":"99ca70d46a3640b3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1800","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":390,"y":160,"wires":[["511d11b641562c6b"]]},{"id":"511d11b641562c6b","type":"http request","z":"99ca70d46a3640b3","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://badetemperaturer.yr.no/api/locations/1-73316/watertemperatures","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"other","keyValue":"apikey","valueType":"other","valueValue":""}],"x":830,"y":160,"wires":[["71de08f0ed88af81"]]},{"id":"d81c10cc4c76b2e7","type":"debug","z":"99ca70d46a3640b3","name":"debug 39","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1300,"y":120,"wires":[]},{"id":"71de08f0ed88af81","type":"json","z":"99ca70d46a3640b3","name":"","property":"payload","action":"obj","pretty":true,"x":1070,"y":160,"wires":[["d81c10cc4c76b2e7","18707207b5f2409d"]]},{"id":"18707207b5f2409d","type":"ha-sensor","z":"99ca70d46a3640b3","name":"","entityConfig":"395a8b7dcabd24f6","version":0,"state":"payload[0].temperature","stateType":"msg","attributes":[{"property":"time","value":"payload[0].time","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":1310,"y":160,"wires":[[]]},{"id":"e1efc409a84fc75e","type":"comment","z":"99ca70d46a3640b3","name":"Change APIKEY and URL","info":"","x":830,"y":120,"wires":[]},{"id":"395a8b7dcabd24f6","type":"ha-entity-config","server":"dc0802f6.645fa","deviceConfig":"","name":"Badetemperatur sjøstrand","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Badetemperatur sjøstrand"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"dc0802f6.645fa","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

 

Også et kort for UI:
 

type: custom:mushroom-template-card
primary: '{{states(''sensor.sjostrand'') +''° '' + ''Sjøstrand'' }}'
secondary: >-
  {{ as_timestamp(state_attr('sensor.sjostrand', 'time'))  |
  timestamp_custom('%d.%m.%Y %H:%M') }}
icon: mdi:coolant-temperature
icon_color: |-
  {% if (states('sensor.sjostrand')|float >= 20) %} 
  red
  {% else %}
  blue
  {% endif %}
multiline_secondary: false
entity: sensor.sjostrand

 

God sommer! 🏖️

 

 

Endret av Petterpotet
Legge til lovelace card
  • Like 1
  • Thanks 1
Skrevet (endret)

Kult, @Petterpotet! Takk som deler.

 

Spm: Jeg bruker ikke NodeRED, og har ikke satt meg så veldig inn i hva NR gjør. Vil dene fungere også uten NodeRED, med en kodesnutt i configuration.yaml og det aktuelle kortet?

 

 

Endret av Teknor

Bli med i samtalen

Du kan publisere innhold nå og registrere deg senere. Hvis du har en konto, logg inn nå for å poste med kontoen din.

Gjest
Skriv svar til emnet...

×   Du har limt inn tekst med formatering.   Lim inn uten formatering i stedet

  Du kan kun bruke opp til 75 smilefjes.

×   Lenken din har blitt bygget inn på siden automatisk.   Vis som en ordinær lenke i stedet

×   Tidligere tekst har blitt gjenopprettet.   Tøm tekstverktøy

×   Du kan ikke lime inn bilder direkte. Last opp eller legg inn bilder fra URL.

×
×
  • Opprett ny...

Viktig informasjon

Vi har plassert informasjonskapsler/cookies på din enhet for å gjøre denne siden bedre. Du kan justere dine innstillinger for informasjonskapsler, ellers vil vi anta at dette er ok for deg.