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! 🏖️