-
Notifications
You must be signed in to change notification settings - Fork 0
/
as_ezo_mqtt_sender_ph.yaml
65 lines (58 loc) · 1.84 KB
/
as_ezo_mqtt_sender_ph.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
globals:
- id: ph_mqtt_timestamp_0
type: int
restore_value: no
initial_value: '0'
- id: ph_mqtt_enabled
type: bool
restore_value: yes
initial_value: ${mqtt_ph_enabled}
number:
- platform: template
min_value: ${min_mqtt_interval_ph}
max_value: ${max_mqtt_interval_ph}
step: "1"
id: ${device_name}_ph_mqtt_sample_interval
name: ${device_name}.ph.mqtt.sample_interval
optimistic: true
mode: box
restore_value : true
initial_value: ${initial_mqtt_interval_ph}
update_interval: "10s"
unit_of_measurement: "ms"
internal: ${mqtt_entities_internal}
switch:
# TEMPERATURE COMPENSATION
- platform: template
name: ${device_name_upper}.ph.mqtt
id: ${device_name}_ph_mqtt
lambda: |-
return id(ph_mqtt_enabled);
turn_on_action:
- lambda: |-
id(ph_mqtt_enabled) = true;
id(ph_mqtt_timestamp_0) = millis();
turn_off_action:
- lambda: |-
id(ph_mqtt_enabled) = false;
internal: ${mqtt_entities_internal}
interval:
- interval: 1s
then:
lambda: |-
if(!${mqtt_entities_internal})
{
if (id(ph_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(ph_mqtt_timestamp_0))
id(ph_mqtt_timestamp_0) = time_now;
// check if we should send a sample
if (time_now - id(ph_mqtt_timestamp_0) >= id(${device_name}_ph_mqtt_sample_interval).state)
{
id(${device_name}_mqtt_client).publish("sensor/${host_name}/ph", to_string(id(${device_name}_ph).state));
id(ph_mqtt_timestamp_0) = time_now;
}
}
}