Issue with data from WGR800

Everything about esp8266 and more.

Moderator: leecollings

hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Issue with data from WGR800

Post by hasselhoffer »

I have a problem with data from an Oregon Scientific WGR800 (433 MHz) not being accepted by Domoticz.
The sensor data is received by RFlink which is then sent over MQTT via an esp8266.
The MQTT data is altered by Node-RED.

Error message presented in Domoticz:
023-10-19 20:05:53.813 Status: Warning: Expecting svalue with at least 5 elements separated by semicolon, 4 elements received ("0;0;1.4;OK"), notification not sent (Hardware: 3 - Virtuella givare, ID: 82027, Unit: 1, Type: 56 - Wind, SubType: 1 - WTGR800)
Domoticz says there should be 5 values ​​but the sensor only has 4, how do I fix this?

This is visible in devices:

27 Virtuella givare 1406B 1 vindmätare Wind WTGR800 0, 1;0;2.1;OK

Sample from Node-RED:
{"command":"udevice","idx":27,"nvalue":0,"svalue":"0;5.7;5;OK"}

I'm grateful for your support.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Issue with data from WGR800

Post by waltervl »

Probably in node red somewhere. Check the source of that solution.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hi @hasselhoffer,

What kind of sensor is that WGR800?

As I read your message, I assume a wind sensor.
However the sensors for wind requires 6 parameters (values)

The only one I'm aware of that uses 5 parameters is the Temperature + Humidity + Barometer sensor

Once I created a kind of model, which you can find at:
viewtopic.php?p=263147&hilit=Humidity+Weather#p263147

This model is starting at my post: 09 Dec 2020, 16:57.

Regards
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: Issue with data from WGR800

Post by hasselhoffer »

Hi @FireWizard,
That's correct. It is an old wind sensor.
This sensor does not have temperature, humidity and barometer values to send.
Regards
Markus
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hi @hasselhoffer,

Nice that you tell the things the sensor doesn't send, but what does the sensor really send.

Connect a debug node to the MQTT input node and copy the result between <>.
Please no screenshot.

Regards
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: Issue with data from WGR800

Post by hasselhoffer »

This is the un altered data:
{"WINDIR":0,"WINGS":4.3,"WINSP":4.6,"BAT":"OK"}
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hi @hasselhoffer,

I see that you receive 3 values, regarding the wind and 1 regarding the battery (OK)

WINDIR is 0 and that means North?
We can calculate the winddirection based on the degrees.

WINDGS is the windgust (4.3)?

WINDSP is the windspeed (4.6)?

The battery is more difficult as it only indicates OK and not a percentage.

Can you confirm my assumptions?

Regards
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: Issue with data from WGR800

Post by hasselhoffer »

Hi @FireWizard,
Yes, your assumption is correct.

Regards
Markus
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hello @hasselhoffer,

I looked to your issue and created a solution in Node-RED

In the picture below, you see a screenshot with the flow and the output of the two debug nodes.

Screenshot_weather_wind_flow.png
Screenshot_weather_wind_flow.png (34.46 KiB) Viewed 1507 times
I have selected "weather/wind" as the topic, but probably you receive a different topic from the ESP8266.
That is okay.

In Debug 199, you see the data that you showed me earlier.

In function 200, I convert this to the format Domoticz requires. (Feel free to change the name)

The contents of this function node is as follows:

Code: Select all

//Insert your Domoticz index number below (Replace 26)
const idx = 26;

// This function sorts the wind direction in abbreviated text for Domoticz based on the average bearing.

function winddir(avgb) {

switch (true) {
    case avgb >= 0 && avgb <= 11.25: { dir = "N" } break;
    case avgb >= 11.26 && avgb <= 33.75: { dir = "NNE" } break;
    case avgb >= 33.76 && avgb <= 56.25: { dir = "NE" } break;
    case avgb >= 56.26 && avgb <= 78.75: { dir = "ENE" } break;
    case avgb >= 78.76 && avgb <= 101.25: { dir = "E" } break;
    case avgb >= 101.26 && avgb <= 123.75: { dir = "ESE" } break;
    case avgb >= 123.76 && avgb <= 146.25: { dir = "SE" } break;
    case avgb >= 146.26 && avgb <= 168.75: { dir = "SSE" } break;
    case avgb >= 168.76 && avgb <= 191.25: { dir = "S" } break;
    case avgb >= 191.26 && avgb <= 213.75: { dir = "SSW" } break;
    case avgb >= 213.76 && avgb <= 236.25: { dir = "SW" } break;
    case avgb >= 236.26 && avgb <= 258.75: { dir = "WSW" } break;
    case avgb >= 258.76 && avgb <= 281.25: { dir = "W" } break;
    case avgb >= 281.26 && avgb <= 303.75: { dir = "WNW" } break;
    case avgb >= 303.76 && avgb <= 326.25: { dir = "NW" } break;
    case avgb >= 326.26 && avgb <= 348.75: { dir = "NNW" } break;
    case avgb >= 348.76 && avgb <= 359.99: { dir = "N" } break;
    default: { dir = "?" } break;
}
return dir;
}

msg.payload = {"command":"udevice", "idx":idx, "svalue":msg.payload.WINDIR + ";" + winddir(msg.payload.WINDIR) + ";" + msg.payload.WINSP * 10 + ";" + msg.payload.WINGS * 10 + ";" + "0" + ";" + "0"};

return msg;
The function winddir is based on the model as presented in the following link: viewtopic.php?p=263147&hilit=Humidity+Weather#p263147

Do the following:

1. Create a virtual hardware device in Domoticz of the type "Dummy" and a sensor of the type "Wind" (Not "Wind + Temp + Chill¨), as we do not have the values for Temperature and Chill.
2. Configure the settings of the MQTT nodes, so that it complies with your MQTT server.
3. Replace in the Function node in the second line, the Domoticz idx number of your sensor.

Check the configuration settings for the "Wind" settings.

Screenshot_wind_widget_config.png
Screenshot_wind_widget_config.png (17.73 KiB) Viewed 1507 times
I left the "Angle Rotation" unchanged, as North equals 0 degrees.
Speed/Gust Multiply: I left it as 1.

This is a new setting, as I remember, it was not there in older versions.
This setting did not work for me, but I have to test it better. Therefore I multiplied the Speed and Gust value with 10 in the Function node.
This was the old solution, as Domoticz accepts the Speed and Gust values in 0.1 m/s

At the end you should see the following result:

Screenshot_wind_widget.png
Screenshot_wind_widget.png (41.02 KiB) Viewed 1507 times
The battery is more complicated as I only see "OK". Does that mean 100%?
What does it show in case the charge is 50% or 10%?

The complete flow below:

Code: Select all

[
    {
        "id": "6480f133a5ba107e",
        "type": "mqtt in",
        "z": "d4b35d52470a739f",
        "name": "MQTT In",
        "topic": "weather/wind",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "108bbff65a6cdbf3",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 900,
        "y": 220,
        "wires": [
            [
                "860c7ff60c59f652",
                "2253ed990f222e59"
            ]
        ]
    },
    {
        "id": "860c7ff60c59f652",
        "type": "debug",
        "z": "d4b35d52470a739f",
        "name": "debug 199",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1090,
        "y": 160,
        "wires": []
    },
    {
        "id": "2253ed990f222e59",
        "type": "function",
        "z": "d4b35d52470a739f",
        "name": "function 20",
        "func": "//Insert your  Domoticz index number below (Replace 26)\nconst idx = 26;\n\n// This function sorts the wind direction in abbreviated text for Domoticz based on the average bearing.\n\nfunction winddir(avgb) {\n\nswitch (true) {\n    case avgb >= 0 && avgb <= 11.25: { dir = \"N\" } break;\n    case avgb >= 11.26 && avgb <= 33.75: { dir = \"NNE\" } break;\n    case avgb >= 33.76 && avgb <= 56.25: { dir = \"NE\" } break;\n    case avgb >= 56.26 && avgb <= 78.75: { dir = \"ENE\" } break;\n    case avgb >= 78.76 && avgb <= 101.25: { dir = \"E\" } break;\n    case avgb >= 101.26 && avgb <= 123.75: { dir = \"ESE\" } break;\n    case avgb >= 123.76 && avgb <= 146.25: { dir = \"SE\" } break;\n    case avgb >= 146.26 && avgb <= 168.75: { dir = \"SSE\" } break;\n    case avgb >= 168.76 && avgb <= 191.25: { dir = \"S\" } break;\n    case avgb >= 191.26 && avgb <= 213.75: { dir = \"SSW\" } break;\n    case avgb >= 213.76 && avgb <= 236.25: { dir = \"SW\" } break;\n    case avgb >= 236.26 && avgb <= 258.75: { dir = \"WSW\" } break;\n    case avgb >= 258.76 && avgb <= 281.25: { dir = \"W\" } break;\n    case avgb >= 281.26 && avgb <= 303.75: { dir = \"WNW\" } break;\n    case avgb >= 303.76 && avgb <= 326.25: { dir = \"NW\" } break;\n    case avgb >= 326.26 && avgb <= 348.75: { dir = \"NNW\" } break;\n    case avgb >= 348.76 && avgb <= 359.99: { dir = \"N\" } break;\n    default: { dir = \"?\" } break;\n}\nreturn dir;\n}\n\nmsg.payload = {\"command\":\"udevice\", \"idx\":idx, \"svalue\":msg.payload.WINDIR + \";\" + winddir(msg.payload.WINDIR) + \";\" + msg.payload.WINSP * 10 + \";\" + msg.payload.WINGS * 10 + \";\" + \"0\" + \";\" + \"0\"};\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1090,
        "y": 220,
        "wires": [
            [
                "fb2f59b92c4759bc",
                "b17241152cf3d2f6"
            ]
        ]
    },
    {
        "id": "fb2f59b92c4759bc",
        "type": "debug",
        "z": "d4b35d52470a739f",
        "name": "debug 200",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1290,
        "y": 160,
        "wires": []
    },
    {
        "id": "b17241152cf3d2f6",
        "type": "mqtt out",
        "z": "d4b35d52470a739f",
        "name": "MQTT to Domoticz",
        "topic": "domoticz/in",
        "qos": "0",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "108bbff65a6cdbf3",
        "x": 1310,
        "y": 220,
        "wires": []
    },
    {
        "id": "108bbff65a6cdbf3",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.10.51",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]
Let me know,

Regards
Last edited by FireWizard on Wednesday 01 November 2023 18:58, edited 3 times in total.
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: Issue with data from WGR800

Post by hasselhoffer »

Hey @FireWizard,

Your solution works great!
Regarding the battery status, as far as I can understand there are only two levels (3 if you count a dead battery).
OK and LOW is what I can see from what is coming out of the RFLink gateway.

Thank you very much for your help, I have not solved this myself.
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hello @hasselhoffer,

I wrote in my previous post:
The battery is more complicated as I only see "OK". Does that mean 100%?
What does it show in case the charge is 50% or 10%?
I studied some documentation of the WGR800 device and I believe the device can only transmit "OK" or "LOW" for the battery.
So it is really okay ("OK") or not okay ("LOW¨). A "dead" battery gives also a low ( = 0V) information

(As your latest post arrived, while I was editing this one, you confirmed it already)

If this is important for you, I suggest the following solution:

Domoticz is able to monitor devices, powered by batteries. Therefore a setting exists.
See:

Screenshot_Other_Settings_Battery.png
Screenshot_Other_Settings_Battery.png (76.38 KiB) Viewed 1485 times
Go to: Setup >> Settings >> Other and you will see it.

In this example I set the fault level to 20 %.
So, if I translate "OK" to 100% and "LOW" to, let's say, 10% it will work. Any value lower than the setting for "Battery Low Level" will work.

In the case of a "LOW" battery message, you will see:

Screenshot_wind_widget_power_low.png
Screenshot_wind_widget_power_low.png (42.76 KiB) Viewed 1485 times

The "Function" node has to be modified a little and looks now:

Code: Select all

//Insert your  Domoticz index number below (Replace 26)
const idx = 26;
let bat;

// This function sorts the wind direction in abbreviated text for Domoticz based on the average bearing.

function winddir(avgb) {

switch (true) {
    case avgb >= 0 && avgb <= 11.25: { dir = "N" } break;
    case avgb >= 11.26 && avgb <= 33.75: { dir = "NNE" } break;
    case avgb >= 33.76 && avgb <= 56.25: { dir = "NE" } break;
    case avgb >= 56.26 && avgb <= 78.75: { dir = "ENE" } break;
    case avgb >= 78.76 && avgb <= 101.25: { dir = "E" } break;
    case avgb >= 101.26 && avgb <= 123.75: { dir = "ESE" } break;
    case avgb >= 123.76 && avgb <= 146.25: { dir = "SE" } break;
    case avgb >= 146.26 && avgb <= 168.75: { dir = "SSE" } break;
    case avgb >= 168.76 && avgb <= 191.25: { dir = "S" } break;
    case avgb >= 191.26 && avgb <= 213.75: { dir = "SSW" } break;
    case avgb >= 213.76 && avgb <= 236.25: { dir = "SW" } break;
    case avgb >= 236.26 && avgb <= 258.75: { dir = "WSW" } break;
    case avgb >= 258.76 && avgb <= 281.25: { dir = "W" } break;
    case avgb >= 281.26 && avgb <= 303.75: { dir = "WNW" } break;
    case avgb >= 303.76 && avgb <= 326.25: { dir = "NW" } break;
    case avgb >= 326.26 && avgb <= 348.75: { dir = "NNW" } break;
    case avgb >= 348.76 && avgb <= 359.99: { dir = "N" } break;
    default: { dir = "?" } break;
}
return dir;
}

if (msg.payload.BAT === "OK") {
    bat = 100
} else if (msg.payload.BAT === "LOW") {
    bat = 10
}

msg.payload = {"command":"udevice", "idx":idx, "svalue":msg.payload.WINDIR + ";" + winddir(msg.payload.WINDIR) + ";" + msg.payload.WINSP * 10 + ";" + msg.payload.WINGS * 10 + ";" + "0" + ";" + "0", "Battery" : bat};

return msg;
The following changes has been made:

NEW: Line 3 added:

Code: Select all

let bat;
NEW : Block with if statements:

Code: Select all

if (msg.payload.BAT === "OK") {
    bat = 100
} else if (msg.payload.BAT === "LOW") {
    bat = 10
}
You can modify these values of 100% and 10%, depending on your setting for "Battery Low Level".

ADDED: "Battery": bat to the line:
msg.payload = {"command":"udevice", "idx":idx, "svalue":msg.payload.WINDIR + ";" + winddir(msg.payload.WINDIR) + ";" + msg.payload.WINSP * 10 + ";" + msg.payload.WINGS * 10 + ";" + "0" + ";" + "0", "Battery" : bat};

Complete new flow:

Code: Select all

[
    {
        "id": "6480f133a5ba107e",
        "type": "mqtt in",
        "z": "d4b35d52470a739f",
        "name": "MQTT In",
        "topic": "weather/wind",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "108bbff65a6cdbf3",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 240,
        "y": 140,
        "wires": [
            [
                "860c7ff60c59f652",
                "2253ed990f222e59"
            ]
        ]
    },
    {
        "id": "860c7ff60c59f652",
        "type": "debug",
        "z": "d4b35d52470a739f",
        "name": "debug 199",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 430,
        "y": 80,
        "wires": []
    },
    {
        "id": "2253ed990f222e59",
        "type": "function",
        "z": "d4b35d52470a739f",
        "name": "function 20",
        "func": "//Insert your  Domoticz index number below (Replace 26)\nconst idx = 26;\nlet bat;\n\n// This function sorts the wind direction in abbreviated text for Domoticz based on the average bearing.\n\nfunction winddir(avgb) {\n\nswitch (true) {\n    case avgb >= 0 && avgb <= 11.25: { dir = \"N\" } break;\n    case avgb >= 11.26 && avgb <= 33.75: { dir = \"NNE\" } break;\n    case avgb >= 33.76 && avgb <= 56.25: { dir = \"NE\" } break;\n    case avgb >= 56.26 && avgb <= 78.75: { dir = \"ENE\" } break;\n    case avgb >= 78.76 && avgb <= 101.25: { dir = \"E\" } break;\n    case avgb >= 101.26 && avgb <= 123.75: { dir = \"ESE\" } break;\n    case avgb >= 123.76 && avgb <= 146.25: { dir = \"SE\" } break;\n    case avgb >= 146.26 && avgb <= 168.75: { dir = \"SSE\" } break;\n    case avgb >= 168.76 && avgb <= 191.25: { dir = \"S\" } break;\n    case avgb >= 191.26 && avgb <= 213.75: { dir = \"SSW\" } break;\n    case avgb >= 213.76 && avgb <= 236.25: { dir = \"SW\" } break;\n    case avgb >= 236.26 && avgb <= 258.75: { dir = \"WSW\" } break;\n    case avgb >= 258.76 && avgb <= 281.25: { dir = \"W\" } break;\n    case avgb >= 281.26 && avgb <= 303.75: { dir = \"WNW\" } break;\n    case avgb >= 303.76 && avgb <= 326.25: { dir = \"NW\" } break;\n    case avgb >= 326.26 && avgb <= 348.75: { dir = \"NNW\" } break;\n    case avgb >= 348.76 && avgb <= 359.99: { dir = \"N\" } break;\n    default: { dir = \"?\" } break;\n}\nreturn dir;\n}\n\nif (msg.payload.BAT === \"OK\") {\n    bat = 100\n} else if (msg.payload.BAT === \"LOW\") {\n    bat = 10\n}\n\nmsg.payload = {\"command\":\"udevice\", \"idx\":idx, \"svalue\":msg.payload.WINDIR + \";\" + winddir(msg.payload.WINDIR) + \";\" + msg.payload.WINSP * 10 + \";\" + msg.payload.WINGS * 10 + \";\" + \"0\" + \";\" + \"0\", \"Battery\" : bat};\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 140,
        "wires": [
            [
                "fb2f59b92c4759bc",
                "b17241152cf3d2f6"
            ]
        ]
    },
    {
        "id": "fb2f59b92c4759bc",
        "type": "debug",
        "z": "d4b35d52470a739f",
        "name": "debug 200",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 630,
        "y": 80,
        "wires": []
    },
    {
        "id": "b17241152cf3d2f6",
        "type": "mqtt out",
        "z": "d4b35d52470a739f",
        "name": "MQTT to Domoticz",
        "topic": "domoticz/in",
        "qos": "0",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "108bbff65a6cdbf3",
        "x": 650,
        "y": 140,
        "wires": []
    },
    {
        "id": "108bbff65a6cdbf3",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.10.51",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]
Nice, that everything is working to your satisfaction.

Regards
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: Issue with data from WGR800

Post by hasselhoffer »

I am very grateful for all the help I have received.
However, I have another question regarding one of my oyher weather sensors.
my rain gauge only reports accumulated value. can I convert this to mm/hr?
this is what the rain gauge reports.
{"RAIN":1311.3,"BAT":"OK"}

If I let a RFlink device be connected to my RPI with USB I get a rain rate value from the same rain gauge.
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hello @hasselhoffer,

You asked:
However, I have another question regarding one of my other weather sensors.
my rain gauge only reports accumulated value. can I convert this to mm/hr?
this is what the rain gauge reports.
{"RAIN":1311.3,"BAT":"OK"}
ans also
f I let a RFlink device be connected to my RPI with USB I get a rain rate value from the same rain gauge.
I assume that the response in both cases is equal.

It is possible to convert this value to mm/hr., but first a few questions.

1. How do you receive the message "{"RAIN":1311.3,"BAT":"OK"}"?
Is it based on time? E.g once per minute or once per 5 minutes? Or once every hour?
Or is based on a changed value of the "Rain" value?

2. Is the value (1311.3) presented in mm or something else(inch)?

If you can give some insight in this?

Regards
Last edited by FireWizard on Wednesday 01 November 2023 19:02, edited 1 time in total.
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: Issue with data from WGR800

Post by hasselhoffer »

Hi @FireWizard,
The value 1311.3 is in mm.
The update interval of the sensor seem to be close to one message each minute.
The same value is repeated until it rains, then the accumulated value starts to rise.

Regards
Markus
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hello @hasselhoffer,

I have looked to your problem and found the following solution:

See the picture below:

Screenshot_Rain_flow.png
Screenshot_Rain_flow.png (14.33 KiB) Viewed 1420 times
Therefore you need to load a custom node, which measures the time between two messages.
It is called "Interval length", but feel free to give it another name

Go to the "Hamburger" menu and select "Manage palette". Clich tab "Install".
Search for "node-red-contrib-interval-length". Install this node.
See: https://flows.nodered.org/node/node-red ... val-length

As said, this node measures the time between two incoming messages and gives it (in this case) in milliseconds.

In the flow: Remove the "Inject" node and replace it by your node giving the output: {"RAIN":1311.3,"BAT":"OK"}.

The "function" node has the following contents:

Code: Select all

const idx = 27;
let bat;

let cur_rainvalue = msg.payload.RAIN;
let prev_rainvalue = flow.get("rainvalue");

if (prev_rainvalue == "undefined") {
    flow.set ("rainvalue", cur_rainvalue);
} else {
    let fallen = cur_rainvalue - prev_rainvalue;
    let rate = fallen / (msg.interval / 360000000);
    flow.set ("rainvalue", cur_rainvalue);
    
    if (msg.payload.BAT === "OK") {
    bat = 100
    } else if (msg.payload.BAT === "LOW") {
    bat = 10
    }

    msg.payload = {"command": "udevice", "idx": idx, "svalue": rate.toFixed().toString() + ";" + fallen.toString(), "Battery" : bat};
    
    return msg;
}
The first line contains the Domoticz idx. Replace it by the idx of your virtual sensor (Rain).
The second line declares the bat value as this is needed for the "Battery". See also the "Wind" sensor.

Also I declared two variables, called cur_rainvalue and prev_rainvalue.
The cur_rainvalue is the current rain value, as just received, while the prev_rainvalue has been received in the previous message.

The next step is to test if the flow variable, called rainvalue has a valid numeric value. It will happen that after a flow restart or deploy the value is undefined. In that case the received value is stored and nothing will happen until the next message is received.

When we receive the next message, I use two variables, fallen and rate, in order to avoid long lines. These variables are used in the final line to the MQTT output to Domoticz. The cur_rainvalue is now stored in the flow variable and will become the prev_rainvalue as the next message arrives.

The value of "fallen" is the difference between the previous value and the current value.
The rate is the same divided by 1000 (from millisecond to seconds) and 3600 (from seconds to hours) and 100.
This is a requirement for Domoticz. See: https://www.domoticz.com/wiki/Domoticz_ ... L%27s#Rain
So totally 360.000.000 (360 million)

As I did not know, whether this is the same battery, as for the Wind sensor or a different one, I also included the Battery part.

Create a virtual "Rain" sensor in your Dummy hardware device and note down the idx number.

If everything is alright, you will get the following:

Screenshot_Rain_widget.png
Screenshot_Rain_widget.png (35.64 KiB) Viewed 1420 times
Do not forget to change the configuration settings of the MQTT node, so that it matches your settings.

See below the complete flow:

Code: Select all

[
    {
        "id": "a8ebc4c23aa074e3",
        "type": "inject",
        "z": "d4b35d52470a739f",
        "name": "Input",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"RAIN\":1333.3,\"BAT\":\"OK\"}",
        "payloadType": "json",
        "x": 250,
        "y": 360,
        "wires": [
            [
                "cf1f444b61aaa14a"
            ]
        ]
    },
    {
        "id": "cf1f444b61aaa14a",
        "type": "interval-length",
        "z": "d4b35d52470a739f",
        "format": "mills",
        "bytopic": false,
        "minimum": "",
        "maximum": "",
        "window": "",
        "timeout": false,
        "msgTimeout": "",
        "minimumunit": "msecs",
        "maximumunit": "msecs",
        "windowunit": "msecs",
        "msgTimeoutUnit": "msecs",
        "reset": false,
        "startup": false,
        "msgField": "interval",
        "timestampField": "timestamp",
        "repeatTimeout": false,
        "name": "",
        "x": 440,
        "y": 360,
        "wires": [
            [
                "b9a92466bc45cba4"
            ],
            []
        ]
    },
    {
        "id": "b9a92466bc45cba4",
        "type": "function",
        "z": "d4b35d52470a739f",
        "name": "To Domoticz",
        "func": "const idx = 27;\nlet bat;\n\nlet cur_rainvalue = msg.payload.RAIN;\nlet prev_rainvalue = flow.get(\"rainvalue\");\n\nif (prev_rainvalue == \"undefined\") {\n    flow.set (\"rainvalue\", cur_rainvalue);\n} else {\n    let fallen = cur_rainvalue - prev_rainvalue;\n    let rate = fallen / (msg.interval / 360000000);\n    flow.set (\"rainvalue\", cur_rainvalue);\n    \n    if (msg.payload.BAT === \"OK\") {\n    bat = 100\n    } else if (msg.payload.BAT === \"LOW\") {\n    bat = 10\n    }\n\n    msg.payload = {\"command\": \"udevice\", \"idx\": idx, \"svalue\": rate.toFixed().toString() + \";\" + fallen.toString(), \"Battery\" : bat};\n    \n    return msg;\n}",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 360,
        "wires": [
            [
                "8f742a18051a24ce",
                "f4315ef89c60f491"
            ]
        ]
    },
    {
        "id": "8f742a18051a24ce",
        "type": "debug",
        "z": "d4b35d52470a739f",
        "name": "debug 201",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 850,
        "y": 320,
        "wires": []
    },
    {
        "id": "f4315ef89c60f491",
        "type": "mqtt out",
        "z": "d4b35d52470a739f",
        "name": "MQTT Out",
        "topic": "domoticz/in",
        "qos": "0",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "108bbff65a6cdbf3",
        "x": 850,
        "y": 360,
        "wires": []
    },
    {
        "id": "108bbff65a6cdbf3",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.10.51",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]
Test it and let me know, if this is what you want.

Regards
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: Issue with data from WGR800

Post by hasselhoffer »

Hello @FireWizard
I implemented your solution with no problem.
It seems to be some kind of issue though.
I get the same value when it's raining as when it's not raining

{"command":"udevice","idx":26,"svalue":"0;0","Battery":100}
nodes1.jpg
nodes1.jpg (33.06 KiB) Viewed 1382 times
nodes.jpg
nodes.jpg (28.3 KiB) Viewed 1382 times
I wonder what's wrong.
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hi @hasselhoffer,

Hmm, this is a difficult one and it is not a simple bug.

While testing this afternoon I saw once NaN (Not a Number). No idea where that came from.
So I have created 3 tests instead of 1. Previously I only tested for "undefined" and I have added a test for other values than a number and a test for "NaN".
This might look strange, but NaN (Not a Number) is a number. So now only real number should pass.

To be sure I have created in the function a 5 debug outputs.

If something goes wrong in your case , can you check the debug outputs (marked with a yellow bar at the left of the debug pane).

It giveindication for (in that order):

1. cur_rainvalue.
2. prev_rainvalue
3. typeof prev_rainvalue == "undefined" || typeof prev_rainvalue != "number" || isNaN(prev_rainvalue)
This one is either true or false. If it is false it should give the values to Domoticz
4. rate (with numbers after the decimal point)
5. fallen (difference of the cur_rainvalue and the prev_rainvalue)

See the node below (Simply replace the other one).

Code: Select all

[
    {
        "id": "b9a92466bc45cba4",
        "type": "function",
        "z": "d4b35d52470a739f",
        "name": "To Domoticz",
        "func": "const idx = 27;\nlet bat;\n\nlet cur_rainvalue = msg.payload.RAIN;\nlet prev_rainvalue = flow.get(\"rainvalue\");\nnode.warn(cur_rainvalue);\nnode.warn(prev_rainvalue);\nnode.warn(typeof prev_rainvalue == \"undefined\" || typeof prev_rainvalue != \"number\" || isNaN(prev_rainvalue));\n\nif (prev_rainvalue == \"undefined\" || typeof prev_rainvalue != \"number\" || isNaN(prev_rainvalue)) {\n    flow.set (\"rainvalue\", cur_rainvalue);\n} else {\n    let fallen = cur_rainvalue - prev_rainvalue;\n    let rate = fallen / (msg.interval / 360000000);\n    flow.set (\"rainvalue\", cur_rainvalue);\n    \n    if (msg.payload.BAT === \"OK\") {\n    bat = 100\n    } else if (msg.payload.BAT === \"LOW\") {\n    bat = 10\n    }\n    node.warn(rate);\n    node.warn(fallen);\n\n    msg.payload = {\"command\": \"udevice\", \"idx\": idx, \"svalue\": rate.toFixed().toString() + \";\" + fallen.toFixed(1).toString(), \"Battery\" : bat};\n    \n    return msg;\n}",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 360,
        "wires": [
            [
                "8f742a18051a24ce"
            ]
        ]
    }
]
Test it carefully and let me know.

Regards
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hi, @hasselhoffer,

During my tests with the "Rain" sensor, I saw also some strange values. Not sure, what caused this, but as this is a cumulative counter, it might be caused by the values I sent.

So have an eye on the following topic: viewtopic.php?f=6&t=40988&sid=6233ab4e8 ... e8db65e7fa

Regards
Last edited by FireWizard on Wednesday 08 November 2023 13:30, edited 1 time in total.
hasselhoffer
Posts: 13
Joined: Wednesday 04 January 2017 17:29
Target OS: Linux
Domoticz version: 2021.1
Location: Sweden
Contact:

Re: Issue with data from WGR800

Post by hasselhoffer »

Hi @FireWizard,

I added the modified node.

Now I don't get only zeros, I get values ​​that change but also warnings?
node 20231106.jpg
node 20231106.jpg (64.93 KiB) Viewed 1346 times
Best regards
Markus
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Issue with data from WGR800

Post by FireWizard »

Hello Markus, @hasselhoffer,

You wrote:
Now I don't get only zeros, I get values ​​that change but also warnings?
I warned you already in my previous post, that this should happen.
To be sure I have created in the function a 5 debug outputs.

If something goes wrong in your case, can you check the debug outputs (marked with a yellow bar at the left of the debug pane).

It give indication for (in that order):

1. cur_rainvalue.
2. prev_rainvalue
3. typeof prev_rainvalue == "undefined" || typeof prev_rainvalue != "number" || isNaN(prev_rainvalue)
This one is either true or false. If it is false it should give the values to Domoticz
4. rate (with numbers after the decimal point)
5. fallen (difference of the cur_rainvalue and the prev_rainvalue)
If we evaluate the outputs received.

The first "warning" shows the cur_rainvalue and that is a number (1333.8).
The second warning shows the prev_rainvalue, which is also the same number (1333.8)
So the conclusion here is, that there was no rainfall in that period and the output is 0
The third output is the result of 3 tests, which shows false. This means that the statements after "else" are executed.
The fourth warning shows NaN. That is strange and we focus on this one.
The fifth warning shows 0 and that matches with our previous conclusion.

In the second run we see a difference (1335.9 - 1333.8) So we have had rain (fallen = 2.1 mm)
This is called "fallen".
Again the NaN.

As said let's focus on the NaN.

I tested it and as the rate = fallen / (msg.interval/360000000)

As you see "fallen" is a Number and, of course, 360000000 also.
The only way to get a NaN is that msg.interval equals to NaN.

This happens, if the setting of the "Interval length" node has bee changed to anything else than "Milliseconds".
So have you changed that to "Human readable" or "JSON object"?

If that is not the case, please show me the result of "debug 203" as a "complete msg object".

Awaiting your answer.

Regards
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests