Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT: refactor messages for better home assistant integration #134

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,19 +1300,19 @@ void push_message(int type, uint32_t lval, float fval, const char* sval) {
case NOTIFY_STATION_ON:

if (os.mqtt.enabled()) {
sprintf_P(topic, PSTR("opensprinkler/station/%d"), lval);
strcpy_P(payload, PSTR("{\"state\":1}"));
sprintf_P(topic, PSTR("opensprinkler/station/%d/state"), lval);
strcpy_P(payload, PSTR("{\"state\":\"on\"}"));
}
break;

case NOTIFY_STATION_OFF:

if (os.mqtt.enabled()) {
sprintf_P(topic, PSTR("opensprinkler/station/%d"), lval);
sprintf_P(topic, PSTR("opensprinkler/station/%d/state"), lval);
if (os.iopts[IOPT_SENSOR1_TYPE]==SENSOR_TYPE_FLOW) {
sprintf_P(payload, PSTR("{\"state\":0,\"duration\":%d,\"flow\":%d.%02d}"), (int)fval, (int)flow_last_gpm, (int)(flow_last_gpm*100)%100);
sprintf_P(payload, PSTR("{\"state\":\"off\",\"duration\":%d,\"flow\":%d.%02d}"), (int)fval, (int)flow_last_gpm, (int)(flow_last_gpm*100)%100);
} else {
sprintf_P(payload, PSTR("{\"state\":0,\"duration\":%d}"), (int)fval);
sprintf_P(payload, PSTR("{\"state\":\"off\",\"duration\":%d}"), (int)fval);
}
}
if (ifttt_enabled) {
Expand Down Expand Up @@ -1344,8 +1344,8 @@ void push_message(int type, uint32_t lval, float fval, const char* sval) {
case NOTIFY_SENSOR1:

if (os.mqtt.enabled()) {
strcpy_P(topic, PSTR("opensprinkler/sensor1"));
sprintf_P(payload, PSTR("{\"state\":%d}"), (int)fval);
strcpy_P(topic, PSTR("opensprinkler/sensor1/state"));
itoa((int)fval, payload, 10);
}
if (ifttt_enabled) {
strcat_P(postval, PSTR("Sensor 1 "));
Expand All @@ -1356,8 +1356,8 @@ void push_message(int type, uint32_t lval, float fval, const char* sval) {
case NOTIFY_SENSOR2:

if (os.mqtt.enabled()) {
strcpy_P(topic, PSTR("opensprinkler/sensor2"));
sprintf_P(payload, PSTR("{\"state\":%d}"), (int)fval);
strcpy_P(topic, PSTR("opensprinkler/sensor2/state"));
itoa((int)fval, payload, 10);
}
if (ifttt_enabled) {
strcat_P(postval, PSTR("Sensor 2 "));
Expand All @@ -1368,8 +1368,8 @@ void push_message(int type, uint32_t lval, float fval, const char* sval) {
case NOTIFY_RAINDELAY:

if (os.mqtt.enabled()) {
strcpy_P(topic, PSTR("opensprinkler/raindelay"));
sprintf_P(payload, PSTR("{\"state\":%d}"), (int)fval);
strcpy_P(topic, PSTR("opensprinkler/raindelay/state"));
strcpy_P(payload, (int)fval ? PSTR("on") : PSTR("off"));
}
if (ifttt_enabled) {
strcat_P(postval, PSTR("Rain delay "));
Expand All @@ -1383,7 +1383,7 @@ void push_message(int type, uint32_t lval, float fval, const char* sval) {
volume = (volume<<8)+os.iopts[IOPT_PULSE_RATE_0];
volume = lval*volume;
if (os.mqtt.enabled()) {
strcpy_P(topic, PSTR("opensprinkler/sensor/flow"));
strcpy_P(topic, PSTR("opensprinkler/sensor/flow/state"));
sprintf_P(payload, PSTR("{\"count\":%d,\"volume\":%d.%02d}"), lval, (int)volume/100, (int)volume%100);
}
if (ifttt_enabled) {
Expand Down Expand Up @@ -1411,8 +1411,8 @@ void push_message(int type, uint32_t lval, float fval, const char* sval) {
case NOTIFY_REBOOT:

if (os.mqtt.enabled()) {
strcpy_P(topic, PSTR("opensprinkler/system"));
strcpy_P(payload, PSTR("{\"state\":\"started\"}"));
strcpy_P(topic, PSTR("opensprinkler/system/power_state"));
strcpy_P(payload, PSTR("on"));
}
if (ifttt_enabled) {
#if defined(ARDUINO)
Expand Down