Push sensor vales to luftdaten

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
3 Likes

I don’t know how my minor brain waves caused you to create this whole script, but judging by reading it it entirely fulfills my needs too :smiley:

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 :smiley:

Aha: you got help from the master himself :smiley:

It’s now up and running fine at my end! There were 2 things I had to change in your script:

  1. You multiplied the pressure with 100 before sending it out; I removed that as a pressure of 101540 Pa seems a bit high

  2. I edited the payload for the opensensemap so it reflected my sensors (the part in bold below)

    {
    5f2XXXXXXXXXXXX”: “{{ states(‘sensor.bme280_temperature’) }}”,
    5f2XXXXXXXXXXXXXXXXXX”: “{{ states(‘sensor.bme280_pressure’) | float * 100 }}”,
    5f2XXXXXXXXXXXXXXXXXX”: “{{ states(‘sensor.bme280_humidity’) }}”,
    5f2XXXXXXXXXXXXXXXXXX”: “{{ states(‘sensor.particulate_matter_2_5um_concentration’) }}”,
    5f2XXXXXXXXXXXXXXXXXX”: “{{ states(‘sensor.particulate_matter_10_0um_concentration’) }}”
    }

EDIT: still figuring out point 1 as your multiplication appears to be correct, but isn’t correctly reflected in the Opensensemap dashboard…

1 Like

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 :slight_smile:
Updated my result above.

Made a small write-up: https://hmmbob.tweakblogs.net/blog/18950/push-data-to-luftdaten-and-opensensemap-with-home-assistant

5 Likes

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:


Can you please help me?

Regards, Edwin.

Is it persistant? I sometimes have these errors too, and either of these two options is happening:

  1. the data I send is invalid (i.e. one of the sensors is listing “unavailable” instead of a normal value)
  2. the API endpoint times out (but this typically doesn’t give you the 400 error.

So, have a good look at your sensor values and see if anything is wrong with them.

Edit: if you want you can shoot me the full error in DM - using the same nickname all over the place (here, discord, Tweakers)

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?

The dht does update every 5minutes.

sensor:
  - platform: sds011
    pm_2_5:
      name: "Particulate Matter <2.5µm Concentration"
      accuracy_decimals: 2
    pm_10_0:
      name: "Particulate Matter <10.0µm Concentration"
      accuracy_decimals: 2
    update_interval: 30min
  - platform: dht
    pin: D7
    temperature:
      name: "Temperature"
      accuracy_decimals: 2
    humidity:
      name: "Humidity"
      accuracy_decimals: 2
    update_interval: 5min

apologies, found the solution elsewhere:

https://community.home-assistant.io/t/sds011-not-updating-at-specified-interval/338892/2?u=rt1080

Great, I was just about to reply that I couldn’t see anything wrong with your code :rofl:

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}'

Verify your sensor ID’s (basically, anything that saus unknown here)

1 Like

Cheers!
I just realized, that my input_text: !include_dir_merge_named was misconfigured, and that caused a chain of errors.

1 Like

I love this project. I’ve adapted the code and currently I’m only pushing data to openSenseMap.org. Since I’m also pushing data from other sensors, that sometimes become unavailable, I’ve had to implement some “error-detection”. My code looks like:

post_opensensebox:
  url: !secret opensensebox_api_url
  method: POST
  headers:
    content-type: "application/json; charset=utf-8"
  payload: >-
    {
      {% if states('sensor.sensorbox_sds0x1_pm2_5') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_pm25') }}": {{ states('sensor.sensorbox_sds0x1_pm2_5') }},
      {% endif %}
      {% if states('sensor.sensorbox_sds0x1_pm10') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_pm10') }}": {{ states('sensor.sensorbox_sds0x1_pm10') }},
      {% endif %}
      {% if states('sensor.weerstation_temperatuur') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_temp') }}": {{ states('sensor.weerstation_temperatuur') }},
      {% endif %}
      {% if states('sensor.weerstation_luchtdruk_absoluut') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_press') }}": {{ ((states('sensor.weerstation_luchtdruk_absoluut') | float) * 100) | round }},
      {% endif %}
      {% if states('sensor.weerstation_luchtvochtigheid') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_hum') }}": {{ states('sensor.weerstation_luchtvochtigheid') }},
      {% endif %}
      {% if states('sensor.lichtsensor_oost_illuminance_lux') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_light_east') }}": {{ states('sensor.lichtsensor_oost_illuminance_lux') }},
      {% endif %}
      {% if states('sensor.lichtsensor_zuid_illuminance_lux') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_light_south') }}": {{ states('sensor.lichtsensor_zuid_illuminance_lux') }},
      {% endif %}
      {% if states('sensor.lichtsensor_west_illuminance_lux') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_light_west') }}": {{ states('sensor.lichtsensor_west_illuminance_lux') }},
      {% endif %}
      {% if states('sensor.weerstation_dauwpunt') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_dewpoint') }}": {{ states('sensor.weerstation_dauwpunt') }},
      {% endif %}
      {% if states('sensor.weerstation_uv') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_uvindex') }}": {{ states('sensor.weerstation_uv') }},
      {% endif %}
      {% if states('sensor.weerstation_windsnelheid') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_windsnelheid') }}": {{ states('sensor.weerstation_windsnelheid') }},
      {% endif %}
      {% if states('sensor.weerstation_windsnelheid_bft') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_windsnelheid_bft') }}": {{ states('sensor.weerstation_windsnelheid_bft') }},
      {% endif %}
      {% if states('sensor.weerstation_windrichting') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_windrichting') }}": {{ states('sensor.weerstation_windrichting') }},
      {% endif %}
      {% if states('sensor.weerstation_neerslag_mm') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_neerslag') }}": {{ states('sensor.weerstation_neerslag_mm') }},
      {% endif %}
      {% if states('sensor.weerstation_neerslag_mm_uur') not in ['unknown', 'unavailable', 'none', 'null'] %}
        "{{ states('input_text.opensensebox_sensorid_neerslag_mm') }}": {{ states('sensor.weerstation_neerslag_mm_uur') }}
      {% endif %}
    }

Since updating to 2004.1 OpenSenseMap has stopped receiving updates and I am seeing the following in the logs:

Logger: homeassistant.components.rest_command
Source: components/rest_command/__init__.py:155
Integration: RESTful Command (documentation, issues)
First occurred: 13:21:49 (1 occurrences)
Last logged: 13:21:49

Error. Url: https://api.opensensemap.org/boxes/61ae21afe0f10a001bc99668/data. Status code 422. Payload: b'{"61ae21afe0f10a001bc9966b": "10.64", "61ae21afe0f10a001bc99669": "101444.34", "61ae21afe0f10a001bc9966a": "64.03", "61ae21afe0f10a001bc9966c": "unknown", "61ae21afe0f10a001bc9966d": "18.00"}'

Anyone have any idea what the cause is and how to fix?

Turns out it was the ‘unknown’ value for the PM2.5 - which was caused because Home Assistant has somehow renamed the entity with a _2 suffix :man_shrugging:

I see that @Hmmbob blog is not available anymore. Does any of you know, where I can find some step-by-step guidance, how to make esphome sensor updating the values to sensor.community?

Yeah, Tweakers took down the blogging platform. However, my code is available on GitHub, maybe that helps? It has some comments embedded in the code to help you get started.

1 Like

Thanks a lot, will try to go through it.