Skip to content

Commit c11ad8a

Browse files
Copilotmatthias-bsCopilot
authored
Add past 24 hours rainfall to examples (#283)
* Initial plan * Add past 24 hours rainfall to all examples using past 60 minutes rainfall Co-authored-by: matthias-bs <83612361+matthias-bs@users.noreply.github.com> * Final update: All tasks completed Co-authored-by: matthias-bs <83612361+matthias-bs@users.noreply.github.com> * Add CodeQL detected source root to .gitignore * Delete _codeql_detected_source_root * Update examples/BresserWeatherSensorDomoticz/BresserWeatherSensorDomoticz.ino Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: matthias-bs <83612361+matthias-bs@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9eee6f7 commit c11ad8a

File tree

7 files changed

+65
-1
lines changed

7 files changed

+65
-1
lines changed

examples/BresserWeatherSensorCanvasGauges/BresserWeatherSensorCanvasGauges.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ String getSensorReadingsBWS()
175175
}
176176

177177
readings["ws_rain_h"] = String(rainGauge.pastHour());
178+
readings["ws_rain_d24h"] = String(rainGauge.past24Hours());
178179
readings["ws_rain_d"] = String(rainGauge.currentDay());
179180
readings["ws_rain_w"] = String(rainGauge.currentWeek());
180181
readings["ws_rain_m"] = String(rainGauge.currentMonth());

examples/BresserWeatherSensorCanvasGauges/data/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ <h1>Weather Sensors</h1>
3838
<div class="card">
3939
<p class="card-title">Rain Gauge</p>
4040
<canvas id="gauge-rainh"></canvas>
41+
<canvas id="gauge-raind24h"></canvas>
4142
<canvas id="gauge-raind"></canvas>
4243
<canvas id="gauge-rainw"></canvas>
4344
<canvas id="gauge-rainm"></canvas>

examples/BresserWeatherSensorCanvasGauges/data/script.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,43 @@ var gaugeRainh = new LinearGauge({
370370
valueDec: 1
371371
}).draw();
372372

373+
var gaugeRaind24h = new LinearGauge({
374+
renderTo: 'gauge-raind24h',
375+
width: 90,
376+
height: 250,
377+
title: "Past 24 hrs",
378+
units: "mm",
379+
minValue: 0,
380+
maxValue: 50,
381+
majorTicks: [
382+
"0",
383+
"10",
384+
"20",
385+
"30",
386+
"40",
387+
"50"
388+
],
389+
minorTicks: 5,
390+
strokeTicks: true,
391+
highlights: false,
392+
colorPlate: "#fff",
393+
colorBar: "#f5f5f5",
394+
colorBarProgress: "#327ac0",
395+
borderShadowWidth: 0,
396+
borders: false,
397+
needleType: "arrow",
398+
needleWidth: 2,
399+
animationDuration: 1500,
400+
animationRule: "linear",
401+
tickSide: "left",
402+
numberSide: "left",
403+
needleSide: "left",
404+
barStrokeWidth: 4,
405+
barBeginCircle: false,
406+
valueInt: 1,
407+
valueDec: 1
408+
}).draw();
409+
373410
var gaugeRaind = new LinearGauge({
374411
renderTo: 'gauge-raind',
375412
width: 90,
@@ -536,6 +573,10 @@ function getReadings() {
536573
var rainh = myObj.ws_rain_h;
537574
gaugeRainh.value = limitValue(rainh, -1, 52);
538575
}
576+
if (myObj.ws_rain_d24h !== undefined) {
577+
var raind24h = myObj.ws_rain_d24h;
578+
gaugeRaind24h.value = limitValue(raind24h, -1, 52);
579+
}
539580
if (myObj.ws_rain_d !== undefined) {
540581
var raind = myObj.ws_rain_d;
541582
gaugeRaind.value = limitValue(raind, -1, 52);
@@ -610,6 +651,9 @@ if (!!window.EventSource) {
610651
if (myObj.ws_rain_h !== undefined) {
611652
gaugeRainh.value = limitValue(myObj.ws_rain_h, -1, 52);
612653
}
654+
if (myObj.ws_rain_d24h !== undefined) {
655+
gaugeRaind24h.value = limitValue(myObj.ws_rain_d24h, -1, 52);
656+
}
613657
if (myObj.ws_rain_d !== undefined) {
614658
gaugeRaind.value = limitValue(myObj.ws_rain_d, -1, 52);
615659
}

examples/BresserWeatherSensorDomoticz/BresserWeatherSensorDomoticz.ino

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@
105105
// BEGIN User specific options
106106
// Please change Domoticz IDX settings according to your configuration
107107
#define DOMO_WIND_IDX 877 // IDX of Domoticz virtual wind sensor
108-
#define DOMO_RAIN_IDX 878 // IDX of Domoticz virtual rain sensor
108+
#define DOMO_RAIN_IDX 878 // IDX of Domoticz virtual rain sensor (hourly)
109+
#define DOMO_RAIN24H_IDX 879 // IDX of Domoticz virtual rain sensor (24h)
109110
#define DOMO_TH_IDX 876 // IDX of Domoticz virtual temperature/humidity sensor
110111
#define PAYLOAD_SIZE 256 // maximum MQTT message size
111112
#define HOSTNAME_SIZE 30 // maximum hostname size
@@ -433,6 +434,14 @@ void publishWeatherdata(void)
433434
domo2_payload += String("\"}");
434435
Serial.printf("%s: %s\n", MQTT_PUB_DOMO, domo2_payload.c_str());
435436
client.publish(MQTT_PUB_DOMO, domo2_payload.c_str(), false, 0);
437+
438+
// Domoticz 24h virtual rain sensor: svalue = "rain_rate;rain_total"
439+
// Report a rate of 0 and the 24h accumulation as the total, without extra scaling.
440+
domo2_payload = String("{\"idx\":") + String(DOMO_RAIN24H_IDX) + String(",\"nvalue\":0,\"svalue\":\"0");
441+
domo2_payload += String(";") + String(rainGauge.past24Hours(), 1);
442+
domo2_payload += String("\"}");
443+
Serial.printf("%s: %s\n", MQTT_PUB_DOMO, domo2_payload.c_str());
444+
client.publish(MQTT_PUB_DOMO, domo2_payload.c_str(), false, 0);
436445
}
437446

438447
// domoticz virtual temp & humidity sensor

examples/BresserWeatherSensorMQTT/src/mqtt_comm.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,13 @@ void publishWeatherdata(bool complete, bool retain)
337337
{
338338
jsonSensor["rain"] = weatherSensor.sensor[i].w.rain_mm;
339339
jsonSensor["rain_h"] = rainGauge.pastHour();
340+
jsonSensor["rain_d24h"] = rainGauge.past24Hours();
340341
jsonSensor["rain_d"] = rainGauge.currentDay();
341342
jsonSensor["rain_w"] = rainGauge.currentWeek();
342343
jsonSensor["rain_m"] = rainGauge.currentMonth();
343344
jsonCombined["ws_rain_mm"] = weatherSensor.sensor[i].w.rain_mm;
344345
jsonCombined["ws_rain_hourly_mm"] = rainGauge.pastHour();
346+
jsonCombined["ws_rain_24h_mm"] = rainGauge.past24Hours();
345347
jsonCombined["ws_rain_daily_mm"] = rainGauge.currentDay();
346348
jsonCombined["ws_rain_weekly_mm"] = rainGauge.currentWeek();
347349
jsonCombined["ws_rain_monthly_mm"] = rainGauge.currentMonth();
@@ -455,6 +457,7 @@ void haAutoDiscovery(void)
455457
{
456458
publishAutoDiscovery(info, "Rainfall", sensor_id, "precipitation", "mm", topic.c_str(), "rain");
457459
publishAutoDiscovery(info, "Rainfall Hourly", sensor_id, "precipitation", "mm", topic.c_str(), "rain_h");
460+
publishAutoDiscovery(info, "Rainfall 24h", sensor_id, "precipitation", "mm", topic.c_str(), "rain_d24h");
458461
publishAutoDiscovery(info, "Rainfall Daily", sensor_id, "precipitation", "mm", topic.c_str(), "rain_d");
459462
publishAutoDiscovery(info, "Rainfall Weekly", sensor_id, "precipitation", "mm", topic.c_str(), "rain_w");
460463
publishAutoDiscovery(info, "Rainfall Monthly", sensor_id, "precipitation", "mm", topic.c_str(), "rain_m");

examples/BresserWeatherSensorMQTTCustom/src/mqtt_comm.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,13 @@ void publishWeatherdata(bool complete, bool retain)
337337
{
338338
jsonSensor["rain"] = weatherSensor.sensor[i].w.rain_mm;
339339
jsonSensor["rain_h"] = rainGauge.pastHour();
340+
jsonSensor["rain_d24h"] = rainGauge.past24Hours();
340341
jsonSensor["rain_d"] = rainGauge.currentDay();
341342
jsonSensor["rain_w"] = rainGauge.currentWeek();
342343
jsonSensor["rain_m"] = rainGauge.currentMonth();
343344
jsonCombined["ws_rain_mm"] = weatherSensor.sensor[i].w.rain_mm;
344345
jsonCombined["ws_rain_hourly_mm"] = rainGauge.pastHour();
346+
jsonCombined["ws_rain_24h_mm"] = rainGauge.past24Hours();
345347
jsonCombined["ws_rain_daily_mm"] = rainGauge.currentDay();
346348
jsonCombined["ws_rain_weekly_mm"] = rainGauge.currentWeek();
347349
jsonCombined["ws_rain_monthly_mm"] = rainGauge.currentMonth();
@@ -455,6 +457,7 @@ void haAutoDiscovery(void)
455457
{
456458
publishAutoDiscovery(info, "Rainfall", sensor_id, "precipitation", "mm", topic.c_str(), "rain");
457459
publishAutoDiscovery(info, "Rainfall Hourly", sensor_id, "precipitation", "mm", topic.c_str(), "rain_h");
460+
publishAutoDiscovery(info, "Rainfall 24h", sensor_id, "precipitation", "mm", topic.c_str(), "rain_d24h");
458461
publishAutoDiscovery(info, "Rainfall Daily", sensor_id, "precipitation", "mm", topic.c_str(), "rain_d");
459462
publishAutoDiscovery(info, "Rainfall Weekly", sensor_id, "precipitation", "mm", topic.c_str(), "rain_w");
460463
publishAutoDiscovery(info, "Rainfall Monthly", sensor_id, "precipitation", "mm", topic.c_str(), "rain_m");

examples/BresserWeatherSensorMQTTWifiMgr/src/mqtt_comm.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,13 @@ void publishWeatherdata(bool complete, bool retain)
337337
{
338338
jsonSensor["rain"] = weatherSensor.sensor[i].w.rain_mm;
339339
jsonSensor["rain_h"] = rainGauge.pastHour();
340+
jsonSensor["rain_d24h"] = rainGauge.past24Hours();
340341
jsonSensor["rain_d"] = rainGauge.currentDay();
341342
jsonSensor["rain_w"] = rainGauge.currentWeek();
342343
jsonSensor["rain_m"] = rainGauge.currentMonth();
343344
jsonCombined["ws_rain_mm"] = weatherSensor.sensor[i].w.rain_mm;
344345
jsonCombined["ws_rain_hourly_mm"] = rainGauge.pastHour();
346+
jsonCombined["ws_rain_24h_mm"] = rainGauge.past24Hours();
345347
jsonCombined["ws_rain_daily_mm"] = rainGauge.currentDay();
346348
jsonCombined["ws_rain_weekly_mm"] = rainGauge.currentWeek();
347349
jsonCombined["ws_rain_monthly_mm"] = rainGauge.currentMonth();
@@ -455,6 +457,7 @@ void haAutoDiscovery(void)
455457
{
456458
publishAutoDiscovery(info, "Rainfall", sensor_id, "precipitation", "mm", topic.c_str(), "rain");
457459
publishAutoDiscovery(info, "Rainfall Hourly", sensor_id, "precipitation", "mm", topic.c_str(), "rain_h");
460+
publishAutoDiscovery(info, "Rainfall 24h", sensor_id, "precipitation", "mm", topic.c_str(), "rain_d24h");
458461
publishAutoDiscovery(info, "Rainfall Daily", sensor_id, "precipitation", "mm", topic.c_str(), "rain_d");
459462
publishAutoDiscovery(info, "Rainfall Weekly", sensor_id, "precipitation", "mm", topic.c_str(), "rain_w");
460463
publishAutoDiscovery(info, "Rainfall Monthly", sensor_id, "precipitation", "mm", topic.c_str(), "rain_m");

0 commit comments

Comments
 (0)