Plugin for own Sensor Data with user-defined station

All about the standard Meteobridge devices based on mobile routers from TP-Link, D-Link, ASUS

Moderator: Mattk

Post Reply
ToTo
Gold Boarder
Gold Boarder
Posts: 255
Joined: Wed Apr 03, 2019 9:24 am
Location: Magdeburg, Germany
Contact:

Plugin for own Sensor Data with user-defined station

Post by ToTo »

I wrote a plugin to use a separate temperature sensor as an alternative indoor sensor instead of the Davis console sensor. The sensor outputs its data as JSON and I created the plugin through trial and error and based on information from the forum. I used the Meteobridge bash to test the commands for extracting the correctly values from the JSON with this sample code:

root@MeteoBridge:~# data=$(wget --timeout=2 -qO- http://192.168.178.34/cm?cmnd=status%2010) && temp=$(echo $data | tr '{'
'\n' | grep Temperature | awk -F '"' '{print substr($3,2,length($3)-2)}') && echo "$temp"
22.2

JSON-Code from sensor:
{"StatusSNS":{"Time":"2026-02-13T20:29:25","SHT4X":{"Temperature":22.2,"Humidity":36.3,"DewPoint":6.5},"TempUnit":"C"}}

plugin Code:
#!/bin/sh
#
#read Temperature, Humidity and Dewpoint data from url file at json format (Tasmota SHT40 Sensor)
#download file from url
#
i=0
while true;
do
data=$(wget --timeout=2 -qO- http://192.168.178.34/cm?cmnd=status%2010)
temp=$(echo $data | tr '{' '\n' | grep Temperature | awk -F '"' '{print substr($3,2,length($3)-2)}')
echo "t0 $temp"
sleep 2
hum=$(echo $data | tr '{' '\n' | grep Temperature | awk -F '"' '{print substr($5,2,length($5)-2)}')
echo "hum0 $hum"
sleep 2
dew=$(echo $data | tr '{' '\n' | grep Temperature | awk -F '"' '{print substr($7,2,length($7)-3)}')
echo "dew0 $dew"
sleep 180
done

For the temperature, Meteobridge displays 2.2 degrees instead of 22.2, even though I am passing 22.2 as a variable, why?

I have integrated the plugin and am getting an error message for the dew point and humidity values.
I'm probably using the wrong variables for dew point and humidity, since the MB Log is showing errors?


Strangely also, even if I delete my userstation I have recorded, the sensor continues to be read. Only restarting the MB helps here!

Who can help me here?
Attachments
IMG_1668.jpeg
IMG_1668.jpeg (53.38 KiB) Viewed 105 times
IMG_1667.jpeg
IMG_1667.jpeg (33.75 KiB) Viewed 105 times
Last edited by ToTo on Sat Feb 14, 2026 4:22 pm, edited 1 time in total.
ToTo
Gold Boarder
Gold Boarder
Posts: 255
Joined: Wed Apr 03, 2019 9:24 am
Location: Magdeburg, Germany
Contact:

Re: Plugin for own Sensor Data with user-defined station

Post by ToTo »

Here is the working plugin version :) :

#!/bin/sh
#
#read Temperature, Humidity data from url file at json format (Tasmota SHT40 Sensor)
# https://templates.blakadder.com/athom_SH01.html
#download file from url
#
i=0
while true;
do
data=$(wget --timeout=2 -qO- http://192.168.178.34/cm?cmnd=status%2010)
temp=$(echo $data | tr '{' '\n' | grep Temperature | awk -F '"' '{print substr($3,2,length($3)-2)*10}')
echo "t0 $temp"
sleep 2
hum=$(echo $data | tr '{' '\n' | grep Temperature | awk -F '"' '{print substr($5,2,length($5)-2)}')
echo "th0 $temp $hum"
sleep 60
done
Attachments
IMG_1669.jpeg
IMG_1669.jpeg (91.4 KiB) Viewed 89 times
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7951
Joined: Mon Oct 01, 2007 10:51 pm

Re: Plugin for own Sensor Data with user-defined station

Post by admin »

Data passed to meteobridge is of type integer. For temperature, rain, wind, pressure the value is send as x10 to provide one decimal of precision even when transported as integer. Therefore, "th0 22 50" will result into 2.2°C and 50% humidity (humidity is not x10 as no decimals are expected).

Thanks for sharing your plug-in code which might help others to implement their own virtual weather station. Please keep in mind that Meteobridge is based on the minimal OPENWRT linux variant and only has ASH as shell, which is a stripped down version of BASH. So shell scripting is a bit more limited as on regular Linux variants using csh or zsh. When more complex operations (like math) are needed, doing this by invoking awk as a good idea - as you did :-)
ToTo
Gold Boarder
Gold Boarder
Posts: 255
Joined: Wed Apr 03, 2019 9:24 am
Location: Magdeburg, Germany
Contact:

Re: Plugin for own Sensor Data with user-defined station

Post by ToTo »

What could be the reason that “malformed data” is output from time to time?

system (03.03.2026 07:15:21): Disconnected from WLAN or Internet, reconnect issued.
system (03.03.2026 07:15:28): Access point operation temporarily enabled.
logger (03.03.2026 07:16:08): station 2 (User-defined), malformed data "t0 "
logger (03.03.2026 07:16:10): station 2 (User-defined), malformed data "th0 "
logger (03.03.2026 07:17:13): station 2 (User-defined), malformed data "t0 "
logger (03.03.2026 07:17:15): station 2 (User-defined), malformed data "th0 "
logger (03.03.2026 07:18:18): station 2 (User-defined), malformed data "t0 "
logger (03.03.2026 07:18:20): station 2 (User-defined), malformed data "th0 "
logger (03.03.2026 07:19:24): station 2 (User-defined), malformed data "t0 "
logger (03.03.2026 07:19:26): station 2 (User-defined), malformed data "th0 "
logger (03.03.2026 07:20:29): station 2 (User-defined), malformed data "t0 "
logger (03.03.2026 07:20:31): station 2 (User-defined), malformed data "th0 "
system (03.03.2026 07:21:16): Disconnected from WLAN or Internet, reconnect issued.
system (03.03.2026 07:21:23): Access point operation temporarily enabled.
logger (03.03.2026 07:21:34): station 2 (User-defined), malformed data "t0 "
logger (03.03.2026 07:21:36): station 2 (User-defined), malformed data "th0 "
logger (03.03.2026 07:22:39): station 2 (User-defined), malformed data "t0 "
logger (03.03.2026 07:22:41): station 2 (User-defined), malformed data "th0 "
logger (03.03.2026 07:23:44): station 2 (User-defined), malformed data "t0 "
logger (03.03.2026 07:23:46): station 2 (User-defined), malformed data "th0 "
logger (03.03.2026 07:24:45): station 1 (AirLink), no signal for 900 seconds, station to be restarted.
logger (03.03.2026 07:24:45): disconnect station 1 (AirLink): timeout
logger (03.03.2026 07:24:50): station 2 (User-defined), malformed data "t0 "
logger (03.03.2026 07:24:52): station 2 (User-defined), malformed data "th0 "
logger (03.03.2026 07:25:15): connect station 1 (AirLink via SW Driver).
system (03.03.2026 07:26:03): Disconnected from WLAN or Internet, reconnect issued.
system (03.03.2026 07:26:10): Access point operation temporarily enabled.
system (03.03.2026 07:31:00): Access point operation disabled 1443960 secs after boot.
system (08.03.2026 17:45:28): Disconnected from WLAN or Internet, reconnect issued.
system (08.03.2026 17:45:36): Access point operation temporarily enabled.
system (08.03.2026 17:51:27): Access point operation disabled 1913187 secs after boot.
Post Reply