-
Notifications
You must be signed in to change notification settings - Fork 0
/
as_ezo_mqtt_sender.yaml
87 lines (76 loc) · 2.83 KB
/
as_ezo_mqtt_sender.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
packages:
as_hydroponics_kit_as_ezo_ec: !include as_ezo_mqtt_sender_ec.yaml
as_hydroponics_kit_as_ezo_ph: !include as_ezo_mqtt_sender_ph.yaml
as_hydroponics_kit_as_ezo_rtd: !include as_ezo_mqtt_sender_rtd.yaml
globals:
- id: combined_mqtt_timestamp_0
type: int
restore_value: no
initial_value: '0'
- id: combined_mqtt_enabled
type: bool
restore_value: yes
initial_value: ${mqtt_combined_enabled}
number:
- platform: template
min_value: ${min_mqtt_interval_combined}
max_value: ${max_mqtt_interval_combined}
step: "1"
id: ${device_name}_combined_mqtt_sample_interval
name: ${device_name}.combined.mqtt.sample_interval
optimistic: true
mode: box
restore_value : true
initial_value: ${initial_mqtt_interval_combined}
update_interval: "10s"
unit_of_measurement: "ms"
internal: ${mqtt_entities_internal}
switch:
# TEMPERATURE COMPENSATION
- platform: template
name: ${device_name_upper}.combined.mqtt
id: ${device_name}_combined_mqtt
lambda: |-
return id(combined_mqtt_enabled);
turn_on_action:
- lambda: |-
id(combined_mqtt_enabled) = true;
id(combined_mqtt_timestamp_0) = millis();
turn_off_action:
- lambda: |-
id(combined_mqtt_enabled) = false;
internal: ${mqtt_entities_internal}
interval:
- interval: 1s
then:
lambda: |-
if(!${mqtt_entities_internal})
{
if (id(combined_mqtt_enabled))
{
int time_now = millis();
// integer overflow protection -> restart waiting timer -> (TODO: maybe implement exact value reset via max integer)
if (time_now < id(combined_mqtt_timestamp_0))
id(combined_mqtt_timestamp_0) = time_now;
// check if we should send a sample
if (time_now - id(combined_mqtt_timestamp_0) >= id(${device_name}_combined_mqtt_sample_interval).state)
{
id(${device_name}_mqtt_client).publish_json("sensor/${host_name}/json", [=](JsonObject root)
{
//root["ph"]["v"] = id(${device_name}_ph).state;
//root["ph"]["u"] = "";
//root["ec"]["v"] = id(${device_name}_ec).state;
//root["ec"]["u"] = "µS/cm";
//root["rtd"]["v"] = id(${device_name}_rtd).state;
//root["rtd"]["u"] = "°C";
root["ph"]["v"] = to_string(id(${device_name}_ph).state);
root["ph"]["u"] = "";
root["ec"]["v"] = to_string(id(${device_name}_ec).state);
root["ec"]["u"] = "µS/cm";
root["rtd"]["v"] = to_string(id(${device_name}_rtd).state);
root["rtd"]["u"] = "°C";
});
id(combined_mqtt_timestamp_0) = time_now;
}
}
}