HowTo: Sensoric from FHEM -> JSON -> WebDesk -> MeshCOM #23
EmEiBee
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Anyone who delves into MeshCOM will likely consider connecting sensors via I²C or similar interfaces to the existing hardware (whether from LilyGo or another manufacturer) to utilize the data; the firmware is designed to transmit this sensor data into the mesh as telemetry, much like a beacon.
However, when operating a node in a fixed location as a repeater and/or gateway, the hardware is usually situated in the attic or outdoor, directly beneath the antenna. Consequently, a connected sensor for temperature, humidity, and air pressure—such as a BME280—would transmit rather nonsensical data into the mesh (with the possible exception of the air pressure reading)...
Yet, anyone running a home automation system — in my case, FHEM — usually already has accurate sensor data available from the sensors linked to that system. So, why not take that data and somehow feed it into the MeshCOM firmware?
It is certainly possible to send data directly from FHEM to the firmware. However, if you also run WebDesk as a service i.e. on a NAS, you are essentially all set. WebDesk already offers a scheduled import feature for telemetry data in JSON format (under Settings/Telemetry). If you can manage to have the WebDesk instance access a file stored within FHEM (or on the system hosting FHEM), you are halfway there (in my case, this was trivial, as FHEM and WebDesk run on the same system).
... the only issue is how to construct a suitable JSON file from FHEM data that WebDesk can actually process. This is where the FHEM forum, and specifically the user "TomLee", came to my aid, ultimately putting together a Perl solution that does exactly that.
You really only need three things:
99_myUtils.pmatcommand to periodically query the devices containing the sensor dataSource and acknowledgments: https://forum.fhem.de/index.php?topic=145058
Enter the following code segment into the file:
Notes:
1.: If the file already contains code, append the new code to the end.
2.: I commented out the timestamp because the WebDesk import function cannot process it (yet).
Notes:
1.: The name "Tele2JSON" can of course be adapted to your specific needs/preferences, as can the interval, etc.
2.: Ensure the path and desired filename in the function call are set correctly. In my case, it is located directly in the FHEM root directory.
3.: The values to be collected from the various devices are comma-separated, using the syntax "Device:Reading:JSON-Key". In other words: the value from the "Reading" of the "Device" is assigned to the key named "JSON-Key" in the JSON file.
Open the WebDesk WebGUI and navigate to Settings / Telemetry. In the "JSON file" field, you must specify the path and filename where WebDesk can find the file generated by FHEM.
For "Destination," group #26299 is specified in my case. #[CountryCode]99 is generally intended for telemetry, at least in Europe. Germany is still undecided on this matter, and it is a subject of controversial debate. You can find more details online or on my blog dj4xi.de in german.
For "Transmission Time," specify the time at which the telemetry data should be sent to the mesh.
Do not enable native telemetry!
Under "Reading Mapping," enter the values written to the JSON alongside the key defined in FHEM (under "JSON-Key"). The identifier is arbitrary but should clearly indicate what the value represents. Due to the mesh's limited payload, long words should generally be avoided...
The "Unit" field is self-explanatory. You can also specify the number of decimal places to transmit and, if applicable, select a suitable icon.
After clicking "Read File & Preview," the contents of the JSON should appear below, displayed clearly in green. Finally, you will see the corresponding LoRa message exactly as it is transmitted with the "TEL" prefix.
Now simply activate it, scroll all the way to the bottom, save, and enjoy...
73 de Micha, DJ4XI
All reactions