sensors-software icon indicating copy to clipboard operation
sensors-software copied to clipboard

How connect sensor to HomeAssistant?

Open andreas-bulling opened this issue 5 years ago • 7 comments

Hi,

I was wondering what the easiest/best way is to get the sensor readings into HomeAssistant. Any standard solutions here (MQTT doesn't seem to be one of them) or people who have been successful with such an integration?

I know that there is a luftdaten component but that requires a detour over the internet...

andreas-bulling avatar Apr 08 '19 22:04 andreas-bulling

It should be possible to change the mentioned component so that it is using the local json endpoint http:///data.json . But this endpoint is shut down for some seconds while the firmware is sending data to the external servers (otherwise the NodeMCU will run out of memory).

ricki-z avatar Apr 10 '19 06:04 ricki-z

@andreas-bulling I also have trouble with the luftdaten component (I wrote the very first version of it but it was refactored so much that I have no idea what it is trying to do now :D). I will now try to use the REST-Component and access the sensor data like this: http://192.168.x.y/data.json

lichtteil avatar Apr 24 '19 08:04 lichtteil

@andreas-bulling I took now my old code of the luftdaten component and changed it so that you can provide the IP address to your local sensor. Feel free to test and give feedback: https://github.com/lichtteil/local_luftdaten

lichtteil avatar Apr 24 '19 12:04 lichtteil

An other option would be to run a rest to mqtt service on your HomeAssistant host (or elsewhere).

It's trivial with IoT.js: https://github.com/SamsungInternet/iotjs-express/commit/0ef4de558396f90886bf4d3f28e252298a2ab05e

I can provide more hints if needed.

rzr avatar Jun 19 '19 13:06 rzr

Hi, I also preferred reading the data directly, here my HA conf for that (if you have other sensors attached) look in ../data.json with your browser and change the number in brackets to the correct position number of the value - of course you probably need also to change the IP):

sensor:

  • platform: command_line name: "Luftdata PM10" command: 'curl http://192.168.70.41/data.json' value_template: "{{ value_json.sensordatavalues[0].value | round(2) }}" unit_of_measurement: "µg/m³"
  • platform: command_line name: "Luftdata PM2.5" command: 'curl http://192.168.70.41/data.json' value_template: "{{ value_json.sensordatavalues[1].value | round(2) }}" unit_of_measurement: "µg/m³"
  • platform: command_line name: "Luftdata Temperature BME280" command: 'curl http://192.168.70.41/data.json' value_template: "{{ value_json.sensordatavalues[2].value | round(1) }}" unit_of_measurement: "°C"
  • platform: command_line name: "Luftdata Humidity BME280" command: 'curl http://192.168.70.41/data.json' value_template: "{{ value_json.sensordatavalues[4].value | round(1) }}" unit_of_measurement: "%"

I assume there is probably even a more elegant way via the rest interface that will probably be able to read the json-date natively but I have not figured it out yet...

UFROF avatar Dec 28 '19 20:12 UFROF

I'm using the rest sensor to fetch the values once and sensor templates to extract all values. This way I can calculate Air Quality Index and a Air Quality Index Description as well. https://gist.github.com/beanieboi/1c94be3d97bd8bb618f3a31bee12c296

beanieboi avatar Dec 29 '20 13:12 beanieboi

thanks beanieboy works perfect. . if not you can always flash the esp to tasmota , it supports the sensor and homeassistant aswel. but it can't be done over the air i think ?

thomasdbnet avatar Jun 06 '22 03:06 thomasdbnet