done = true;
}
+ # Publish a value to Domoticz as an nvalue
+ - id: tell_domo_nvalue
+ mode: queued
+ parameters:
+ udevice: int
+ nvalue: int
+ then:
+ lambda: |-
+ id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
+ root["command"] = "udevice";
+ root["idx"] = udevice;
+ root["nvalue"] = nvalue;
+ });
+
+ # Publish a value to Domoticz as an svalue
+ - id: tell_domo_svalue
+ mode: queued
+ parameters:
+ udevice: int
+ svalue: string
+ then:
+ lambda: |-
+ id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
+ root["command"] = "udevice";
+ root["idx"] = udevice;
+ root["svalue"] = svalue;
+ });
+
globals:
- id: solar_in_fails # Number of minutes without a reading.
type: int
password: !secret pool_mqtt_pw
id: mqtt_client
on_connect:
- then:
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 512;
- root["nvalue"] = id(valve_output).state ? 1 : 0;
+ then:
+ - delay: 2s # Too soon and the first messages don't get through!
+ - lambda: |-
+ id(tell_domo_nvalue)->execute(512, id(valve_output).state);
+ id(tell_domo_nvalue)->execute(515, id(pool_light).state);
+ id(tell_domo_nvalue)->execute(516, id(patio_light).state);
+ id(tell_domo_nvalue)->execute(517, id(shed_fan).state);
+ id(tell_domo_nvalue)->execute(518, id(pool_pump).state);
on_json_message:
- topic: domoticz/out
auto cumulative = x["electricitymeter"]["energy"]["import"]["cumulative"];
int kwh, watts;
if (cumulative) {
- // { "command" : "udevice", "idx" : 29, "svalue" : $cumulative }
kwh = (cumulative.as<double>() * 1000.0f) + 0.1f;
- id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
- root["command"] = "udevice";
- root["idx"] = 29;
- root["svalue"] = std::to_string(kwh);
- });
+ id(tell_domo_svalue)->execute(29, std::to_string(kwh));
}
auto power = x["electricitymeter"]["power"]["value"];
if (power) {
watts = (power.as<double>() * 1000.0f) + 0.1f;
- // { "command" : "udevice", "idx" : 25, "svalue" : $power }
- id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
- root["command"] = "udevice";
- root["idx"] = 24;
- root["svalue"] = std::to_string(watts);
- });
+ id(tell_domo_svalue)->execute(24, std::to_string(watts));
}
if (cumulative && power) {
- id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
- root["command"] = "udevice";
- root["idx"] = 514;
- root["svalue"] = std::to_string(watts) + ";" + std::to_string(kwh);
- });
+ id(tell_domo_svalue)->execute(514, std::to_string(watts) + ";" + std::to_string(kwh));
}
dallasng:
then:
lambda: |-
id(solar_in_fails) = 0;
- id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
- root["command"] = "udevice";
- root["idx"] = 507;
- root["svalue"] = std::to_string(x);
- });
+ id(tell_domo_svalue)->execute(507, std::to_string(x));
id(control_valve)->execute();
- platform: dallasng
then:
- lambda: |-
id(solar_out_fails) = 0;
- id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
- root["command"] = "udevice";
- root["idx"] = 508;
- root["svalue"] = std::to_string(x);
- });
+ id(tell_domo_svalue)->execute(508, std::to_string(x));
id(control_valve)->execute();
# - platform: dallasng
on_value:
then:
lambda: |-
- id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
- root["command"] = "udevice";
- root["idx"] = 510;
- root["svalue"] = std::to_string(x);
- });
+ id(tell_domo_svalue)->execute(510, std::to_string(x));
- platform: template
name: "BLE-YC01 ORP"
on_value:
then:
lambda: |-
- id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
- root["command"] = "udevice";
- root["idx"] = 511;
- root["svalue"] = std::to_string(x);
- });
+ id(tell_domo_svalue)->execute(511, std::to_string(x));
- platform: template
name: "BLE-YC01 battery"
on_value:
then:
lambda: |-
- id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
- root["command"] = "udevice";
- root["idx"] = 519;
- root["svalue"] = std::to_string(x);
- });
+ id(tell_domo_svalue)->execute(519, std::to_string(x));
- platform: template
name: "BLE-YC01 CL"
on_value:
then:
lambda: |-
- id(mqtt_client).publish_json("domoticz/in", [=](JsonObject root) {
- root["command"] = "udevice";
- root["idx"] = 509;
- root["svalue"] = std::to_string(x);
- });
+ id(tell_domo_svalue)->execute(509, std::to_string(x));
- platform: ble_client
type: rssi
on_turn_on:
then:
- light.turn_on: green_led
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 512;
- root["nvalue"] = 1;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 512
+ nvalue: 1
on_turn_off:
then:
- light.turn_off: green_led
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 512;
- root["nvalue"] = 0;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 512
+ nvalue: 0
- platform: gpio
id: power_1w
inverted: true
on_turn_on:
then:
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 516;
- root["nvalue"] = 1;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 516
+ nvalue: 1
on_turn_off:
then:
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 516;
- root["nvalue"] = 0;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 516
+ nvalue: 0
- platform: gpio
id: pool_pump
inverted: true
on_turn_on:
then:
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 518;
- root["nvalue"] = 1;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 518
+ nvalue: 1
on_turn_off:
then:
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 518;
- root["nvalue"] = 0;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 518
+ nvalue: 0
- platform: gpio
id: pool_light
inverted: true
on_turn_on:
then:
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 515;
- root["nvalue"] = 1;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 515
+ nvalue: 1
on_turn_off:
then:
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 515;
- root["nvalue"] = 0;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 515
+ nvalue: 0
- platform: gpio
id: shed_fan
inverted: true
on_turn_on:
then:
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 517;
- root["nvalue"] = 1;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 517
+ nvalue: 1
on_turn_off:
then:
- - mqtt.publish_json:
- topic: domoticz/in
- payload: |-
- root["command"] = "udevice";
- root["idx"] = 517;
- root["nvalue"] = 0;
+ - script.execute:
+ id: tell_domo_nvalue
+ udevice: 517
+ nvalue: 0