-
Notifications
You must be signed in to change notification settings - Fork 0
/
as_ezo_mqtt_sender_ec.yaml
113 lines (103 loc) · 3.64 KB
/
as_ezo_mqtt_sender_ec.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
globals:
- id: ec_mqtt_timestamp_0
type: int
restore_value: no
initial_value: '0'
- id: ec_mqtt_enabled
type: bool
restore_value: yes
initial_value: ${mqtt_ec_enabled}
number:
- platform: template
min_value: ${min_mqtt_interval_ec}
max_value: ${max_mqtt_interval_ec}
step: "1"
id: ${device_name}_ec_mqtt_sample_interval
name: ${device_name}.ec.mqtt.sample_interval
optimistic: true
mode: box
restore_value : true
initial_value: ${initial_mqtt_interval_ec}
update_interval: "10s"
unit_of_measurement: "ms"
internal: ${mqtt_entities_internal}
switch:
# TEMPERATURE COMPENSATION
- platform: template
name: ${device_name_upper}.ec.mqtt
id: ${device_name}_ec_mqtt
lambda: |-
return id(ec_mqtt_enabled);
turn_on_action:
- lambda: |-
id(ec_mqtt_enabled) = true;
id(ec_mqtt_timestamp_0) = millis();
turn_off_action:
- lambda: |-
id(ec_mqtt_enabled) = false;
internal: ${mqtt_entities_internal}
on_turn_on:
then:
- mqtt.publish:
topic: some/topic
payload: "Something happened!"
# Templated:
- mqtt.publish:
topic: !lambda |-
if (id(${device_name}_ec_mqtt).state) return "topic1";
else return "topic2";
payload: !lambda |-
return id(${device_name}_ec_mqtt).state ? "YES" : "NO";
interval:
- interval: 1s
then:
# - if:
# condition:
# lambda: |-
# return !${mqtt_entities_internal};
# then:
# - if:
# condition:
# lambda: |-
# return id(ec_mqtt_enabled);
# then:
# - if:
# condition:
# lambda: |-
# int time_now = millis();
# // integer overflow protection -> restart waiting timer -> (TODO: maybe implement exact value reset via max integer)
# if (time_now < id(ec_mqtt_timestamp_0))
# id(ec_mqtt_timestamp_0) = time_now;
#
# // check if we should send a sample
# if (time_now - id(ec_mqtt_timestamp_0) >= id(${device_name}_ec_mqtt_sample_interval).state)
# return true;
# else
# return false;
# then:
# - mqtt.publish:
# topic: !lambda |-
# return "${host_name}/ec";
# payload: !lambda |-
# return to_string(id(${device_name}_ec).state);
#
# else:
# else:
# else:
lambda: |-
if(!${mqtt_entities_internal})
{
if (id(ec_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(ec_mqtt_timestamp_0))
id(ec_mqtt_timestamp_0) = time_now;
// check if we should send a sample
if (time_now - id(ec_mqtt_timestamp_0) >= id(${device_name}_ec_mqtt_sample_interval).state)
{
id(${device_name}_mqtt_client).publish("sensor/${host_name}/ec", to_string(id(${device_name}_ec).state));
id(ec_mqtt_timestamp_0) = time_now;
}
}
}