einwetter.de - Eine kurze Übersicht
Smarthome bei Christian Zuhause
graph TB
user[Benutzer] --> hass
user --> grafana
subgraph Smarthome
hass[Home Assistant] --> influx[InfluxDB]
grafana[Grafana] --> influx
mqtt[MQTT Bus] --> hass
esp1[ESP Outdoor] -- Wifi --> mqtt
esp2[ESP Wohnzimmer] -- Wifi --> mqtt
esp3[ESP Schlafzimmer] -- Wifi --> mqtt
end
subgraph einwetter
cron[Alle 10 Minuten] --> script
script[Export Script] --> hass
script --> upload[Datei Upload]
upload --> website[wetter.brickburg.de]
end
Upload Script für Home Assistant
hass-opendata.sh
#!/bin/bash
set -e
set -u
curl -X GET -L --silent \
-H "Authorization: Bearer YYYYYYYYYYYYYYYYYYYY" \
-H "Content-Type: application/json" \
https://hass.brickburg.de/api/states | \
jq '
.[] |
select( .entity_id == "sensor.outdoor_temperature_min" or .entity_id == "sensor.outdoor_temperature_max" or .entity_id == "sensor.kitchen_outdoor_humidity" ) |
{
"name": .entity_id | sub("sensor.";"") | sub("outdoor_";"") | sub("kitchen_";""),
"value": .state | tonumber,
"value_unit": .attributes.unit_of_measurement,
"last_updated": .last_updated,
"last_changed": .last_changed
}
' | \
jq -s . | \
jq -M --arg now "$(date +"%Y-%m-%dT%H:%M:%S%z")" \
'{
"measurements": .,
"location": {
"position": [ 51.811787, 9.857394 ],
"street": "Wankemühlenweg",
"zip": "37574",
"city": "Einbeck",
"state": "Lower Saxony",
"country": "Germany"
},
"generated_date": $now
}'
hass-opendata-upload.sh
#!/bin/bash
set -u
set -e
export SSH_AUTH_SOCK=/home/christian/.ssh/ssh-agent.ellen.sock
ssh-add -l 2>/dev/null >/dev/null
if [ $? -ge 2 ]; then
exit 1
fi
/home/christian/bin/hass-opendata.sh | ssh w00ffa8d.kasserver.com "cat >/www/htdocs/w00ffa8d/vhosts/de.brickburg.einbeck/weather.json"
Beispiel Format
{
"measurements": [
{
"name": "temperature_min",
"value": 16,
"value_unit": "°C",
"last_updated": "2021-07-06T21:46:37.234897+00:00",
"last_changed": "2021-07-06T21:44:46.607061+00:00"
},
{
"name": "temperature_max",
"value": 16.9,
"value_unit": "°C",
"last_updated": "2021-07-06T21:46:37.235016+00:00",
"last_changed": "2021-07-06T21:46:37.235016+00:00"
},
{
"name": "humidity",
"value": 43.5,
"value_unit": "%",
"last_updated": "2021-07-06T21:48:06.598966+00:00",
"last_changed": "2021-07-06T21:48:06.598966+00:00"
}
],
"location": {
"position": [
51.811787,
9.857394
],
"street": "Wankemühlenweg",
"zip": "37574",
"city": "Einbeck",
"state": "Lower Saxony",
"country": "Germany"
},
"generated_date": "2021-07-06T23:50:01+0200"
}