I have been looking into a way to push sensor values to luftdaten.info. Up until now the only option I have found is to install the luftdaten firmware on my wemos or ESP32 devices and then get the data back into Homeassistant via the Luftdaten sensor. This however conflicts a little bit with my, and the homeassistant, philosophy that Homeassistant should not have to rely on cloud services and operate locally as much as possible. I would therefore ideally like to rely on the robust esphome integration and afterwards push values to Luftdaten from within Homeassistant.
When moving to ESPHome to drive the device the high level approach would be:
Configure device to present sensors of PM2.5 and PM10 to Home Assistant (standard ESPHome functionality).
Create rest_command that points to the Luftdaten API URL you have already found. The payload of the command will be configured as a template and contains some fixed data (like your sensor ID) as well as some variable data (like the current sensor values).
Create automation that gets triggered every time the PM2.5 and PM10 are both updated, and in the action call the rest_command.
I just captured the payload that my sensor has sent:
Did any of you get around this? I just built a nice sensor with my oldest son, found the luftdaten ācloud detourā to get data into HA too cumbersome, so I set up a ESPHome device and am able to get all data in HA. Iād still like to push the data to Luftdaten though.
Find the ID of the sensor you would like to update (go to https://opensensemap.org/account click under the right sensebox āEDITā, Sensors and find the long sensor ID)
Thanks, you put me on the right track. Iāve got it all implemented right now.
So, assuming that you already have the data available in Home Assistant, one could use the following automation to push:
As you can see, the automation calls for 4 rest_commands. These are defined as follows:
As the rest_commands cannot process !secrets, I used a workaround via input_text:
Secrets explained:
!secret luftdaten_x_sensor: contains Luftdaten sensor ID (typically something like esp8266-123456)
!secret opensensebox_url: contains API endpoint for this sensor box (something like https://api.opensensemap.org/boxes/<<yourSenseBoxID>>/data
It was a learning opportunity, I built this sensor together with my son (10) and he wanted to upload the data too. So we made it happen.
And kudos to Frenck for helping me tweaking the scripts too. Had an initial proof-of-concept, but that had a lot of duplicate code. Thanks to his input i was able to simplify the script considerably.
And yes - your brainwave put me on the right track
Yeah, I had to do the multiplication as the value in HA is in hPa, while the APIs are expecting Pa. And you are right, you need to change those values in 2) to your own sensor IDs. Iāll update the file on Github with a note (seems I canāt use !secret there?)
edit: fixed it in a new upload, using input_text with !secret now
Updated my result above.
Hi Bob,
I followed your instructions on Tweakblogs. I get all the information in Home Assistant but i canāt push it to opensensemap. Here is my error in HA:
Hi, i built the sensor last year and just migrated it from the standard luftdaten firmware to esphome - followed the blog and itās working; however, my SDS updates every couple of seconds as opposed to the 30min I put in the script; any thoughts what might going wrong here?
Can you confirm this is still working?
Iām getting the following error: 2022-07-26 19:51:36 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: https://api.opensensemap.org/boxes/xxxxxxxxxxxxx/data. Status code 422. Payload: b'{\n "unknown": "2.2",\n "unknown": "9.2",\n "unknown": "6.91",\n "unknown": "100527",\n "unknown": "80.79"\n}'