-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
1845 lines (1455 loc) · 86.9 KB
/
__init__.py
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab
#########################################################################
# Copyright 2020- Martin Sinn [email protected]
# Copyright 2021- Michael Wenzel [email protected]
#########################################################################
# This file is part of SmartHomeNG.
#
# SmartHomeNG is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SmartHomeNG is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SmartHomeNG. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
from datetime import datetime, timedelta
from lib.model.mqttplugin import *
from .webif import WebInterface
class Tasmota(MqttPlugin):
"""
Main class of the Plugin. Does all plugin specific stuff and provides the update functions for the items
"""
PLUGIN_VERSION = '1.3.1'
LIGHT_MSG = ['HSBColor', 'Dimmer', 'Color', 'CT', 'Scheme', 'Fade', 'Speed', 'LedTable', 'White']
RF_MSG = ['RfSync', 'RfLow', 'RfHigh', 'RfCode']
ZIGBEE_BRIDGE_DEFAULT_OPTIONS = {'SetOption89': 'OFF',
'SetOption101': 'OFF',
'SetOption120': 'OFF',
'SetOption83': 'ON',
'SetOption112': 'OFF',
'SetOption110': 'OFF',
'SetOption119': 'OFF',
'SetOption118': 'OFF',
'SetOption125': 'ON',
}
TASMOTA_ATTR_R_W = ['relay', 'hsb', 'white', 'ct', 'rf_send', 'rf_key_send', 'zb_permit_join', 'zb_forget', 'zb_ping', 'rf_key']
TASMOTA_ZB_ATTR_R_W = ['power', 'hue', 'sat', 'ct', 'dimmer', 'ct_k']
ENERGY_SENSOR_KEYS = {'Voltage': 'item_voltage',
'Current': 'item_current',
'Power': 'item_power',
'ApparentPower': 'item_apparent_power',
'ReactivePower': 'item_reactive_power',
'Factor': 'item_power_factor',
'TotalStartTime': 'item_total_starttime',
'Total': 'item_power_total',
'Yesterday': 'item_power_yesterday',
'Today': 'item_power_today'}
ENV_SENSOR = ['DS18B20', 'AM2301', 'SHT3X', 'BMP280', 'DHT11']
ENV_SENSOR_KEYS = {'Temperature': 'item_temp',
'Humidity': 'item_hum',
'DewPoint': 'item_dewpoint',
'Pressure': 'item_pressure',
'Id': 'item_1wid'}
ANALOG_SENSOR_KEYS = {'Temperature': 'item_analog_temp',
'Temperature1': 'item_analog_temp1',
'A0': 'item_analog_a0',
'Range': 'item_analog_range'}
ESP32_SENSOR_KEYS = {'Temperature': 'item_esp32_temp'}
SENSORS = [*ENV_SENSOR,
'ENERGY',
]
def __init__(self, sh):
"""
Initializes the plugin.
"""
# Call init code of parent class (MqttPlugin)
super().__init__()
if not self._init_complete:
return
# get the parameters for the plugin (as defined in metadata plugin.yaml):
self.webif_pagelength = self.get_parameter_value('webif_pagelength')
self.telemetry_period = self.get_parameter_value('telemetry_period')
# crate full_topic
self.full_topic = self.get_parameter_value('full_topic').lower()
if self.full_topic.find('%prefix%') == -1 or self.full_topic.find('%topic%') == -1:
self.full_topic = '%prefix%/%topic%/'
if self.full_topic[-1] != '/':
self.full_topic += '/'
# Define properties
self.tasmota_devices = {} # to hold tasmota device information for web interface
self.tasmota_zigbee_devices = {} # to hold tasmota zigbee device information for web interface
self.tasmota_items = [] # to hold item information for web interface
self.topics_of_retained_messages = [] # to hold all topics of retained messages
# NEW
self.tasmota_objects_dict = TasmotaDevices()
self.alive = None
# Add subscription to get device discovery
self.add_subscription( 'tasmota/discovery/#', 'dict', callback=self.on_mqtt_discovery_message)
# Add subscription to get device LWT
self.add_tasmota_subscription('tele', '+', 'LWT', 'bool', bool_values=['Offline', 'Online'], callback=self.on_mqtt_lwt_message)
# Add subscription to get device status
self.add_tasmota_subscription('stat', '+', 'STATUS0', 'dict', callback=self.on_mqtt_status0_message)
# Add subscription to get device actions result
self.add_tasmota_subscription('stat', '+', 'RESULT', 'dict', callback=self.on_mqtt_message)
# Init WebIF
self.init_webinterface(WebInterface)
return
def run(self):
"""
Run method for the plugin
"""
self.logger.debug("Run method called")
# start subscription to all defined topics
self.start_subscriptions()
self.logger.debug(f"Scheduler: 'check_online_status' created")
dt = self.shtime.now() + timedelta(seconds=(self.telemetry_period - 3))
self.scheduler_add('check_online_status', self.check_online_status, cycle=self.telemetry_period, next=dt)
self.logger.debug(f"Scheduler: 'add_tasmota_subscriptions' created")
self.scheduler_add('add_tasmota_subscriptions', self.add_tasmota_subscriptions, cron='init+20')
self.alive = True
def stop(self):
"""
Stop method for the plugin
"""
self.alive = False
self.logger.debug("Stop method called")
self.scheduler_remove('check_online_status')
# stop subscription to all topics
self.stop_subscriptions()
def parse_item(self, item):
"""
Default plugin parse_item method. Is called when the plugin is initialized.
The plugin can, corresponding to its attribute keywords, decide what to do with
the item in the future, like adding it to an internal array for future reference
:param item: The item to process.
:return: If the plugin needs to be informed of an items change you should return a call back function
like the function update_item down below. An example when this is needed is the knx plugin
where parse_item returns the update_item function when the attribute knx_send is found.
This means that when the items value is about to be updated, the call back function is called
with the item, caller, source and dest as arguments and in case of the knx plugin the value
can be sent to the knx with a knx write function within the knx plugin.
"""
if self.has_iattr(item.conf, 'tasmota_topic'):
tasmota_topic = self.get_iattr_value(item.conf, 'tasmota_topic')
self.logger.info(f"parsing item: {item.id()} with tasmota_topic={tasmota_topic}")
tasmota_attr = self.get_iattr_value(item.conf, 'tasmota_attr')
tasmota_relay = self.get_iattr_value(item.conf, 'tasmota_relay')
tasmota_rf_details = self.get_iattr_value(item.conf, 'tasmota_rf_key')
tasmota_zb_device = self.get_iattr_value(item.conf, 'tasmota_zb_device')
tasmota_zb_group = self.get_iattr_value(item.conf, 'tasmota_zb_group')
tasmota_zb_attr = self.get_iattr_value(item.conf, 'tasmota_zb_attr')
tasmota_zb_attr = tasmota_zb_attr.lower() if tasmota_zb_attr else None
tasmota_sml_device = self.get_iattr_value(item.conf, 'tasmota_sml_device')
tasmota_sml_attr = self.get_iattr_value(item.conf, 'tasmota_sml_attr')
tasmota_sml_attr = tasmota_sml_attr.lower() if tasmota_sml_attr else None
# handle tasmota devices without zigbee
if tasmota_attr:
self.logger.info(f"Item={item.id()} identified for Tasmota with tasmota_attr={tasmota_attr}")
tasmota_attr = tasmota_attr.lower()
tasmota_relay = 1 if not tasmota_relay else tasmota_relay
if tasmota_rf_details and '=' in tasmota_rf_details:
tasmota_rf_details, tasmota_rf_key_param = tasmota_rf_details.split('=')
# handle tasmota zigbee devices
elif tasmota_zb_device and tasmota_zb_attr:
self.logger.info(f"Item={item.id()} identified for Tasmota Zigbee with tasmota_zb_device={tasmota_zb_device} and tasmota_zb_attr={tasmota_zb_attr}")
# check if zigbee device short name has been used without parentheses; if so this will be normally parsed to a number and therefore mismatch with definition
try:
tasmota_zb_device = int(tasmota_zb_device)
self.logger.warning(f"Probably for item {item.id()} the device short name as been used for attribute 'tasmota_zb_device'. Trying to make that work but it will cause exceptions. To prevent this, the short name need to be defined as string by using parentheses")
tasmota_zb_device = str(hex(tasmota_zb_device))
tasmota_zb_device = tasmota_zb_device[0:2] + tasmota_zb_device[2:len(tasmota_zb_device)].upper()
except Exception:
pass
# handle tasmota zigbee groups
elif tasmota_zb_group and tasmota_zb_attr:
self.logger.info(f"Item={item.id()} identified for Tasmota Zigbee with tasmota_zb_group={tasmota_zb_group} and tasmota_zb_attr={tasmota_zb_attr}")
# handle tasmota smartmeter devices
elif tasmota_sml_device and tasmota_sml_attr:
self.logger.info(f"Item={item.id()} identified for Tasmota SML with tasmota_sml_device={tasmota_sml_device} and tasmota_sml_attr={tasmota_sml_attr}")
# handle everything else
else:
self.logger.info(f"Definition of attributes for item={item.id()} incomplete. Item will be ignored.")
return
# setup dict for new device
if not self.tasmota_devices.get(tasmota_topic):
self._add_new_device_to_tasmota_devices(tasmota_topic)
self.tasmota_devices[tasmota_topic]['status'] = 'item.conf'
# fill tasmota_device dict
self.tasmota_devices[tasmota_topic]['connected_to_item'] = True
if tasmota_attr == 'relay' and tasmota_relay:
item_type = f'item_{tasmota_attr}{tasmota_relay}'
elif tasmota_attr == 'rf_key' and tasmota_rf_details:
item_type = f'item_{tasmota_attr}{tasmota_rf_details}'
elif tasmota_zb_device and tasmota_zb_attr:
item_type = f'item_{tasmota_zb_device}.{tasmota_zb_attr}'
elif tasmota_sml_device and tasmota_sml_attr:
item_type = f'item_{tasmota_sml_device}.{tasmota_sml_attr}'
else:
item_type = f'item_{tasmota_attr}'
self.tasmota_devices[tasmota_topic]['connected_items'][item_type] = item
# append to list used for web interface
if item not in self.tasmota_items:
self.tasmota_items.append(item)
return self.update_item
elif self.has_iattr(item.conf, 'tasmota_admin'):
self.logger.debug(f"parsing item: {item.id()} for tasmota admin attribute")
return self.update_item
def update_item(self, item, caller: str = None, source: str = None, dest: str = None):
"""
Item has been updated
This method is called, if the value of an item has been updated by SmartHomeNG.
It should write the changed value out to the device (hardware/interface) that
is managed by this plugin.
:param item: item to be updated towards the plugin
:param caller: if given it represents the callers name
:param source: if given it represents the source
:param dest: if given it represents the dest
"""
if self.alive and caller != self.get_shortname():
# code to execute if the plugin is not stopped AND only, if the item has not been changed by this plugin:
# get tasmota attributes of item
tasmota_admin = self.get_iattr_value(item.conf, 'tasmota_admin')
tasmota_topic = self.get_iattr_value(item.conf, 'tasmota_topic')
tasmota_attr = self.get_iattr_value(item.conf, 'tasmota_attr')
tasmota_relay = self.get_iattr_value(item.conf, 'tasmota_relay')
tasmota_relay = '1' if not tasmota_relay else None
tasmota_rf_details = self.get_iattr_value(item.conf, 'tasmota_rf_details')
tasmota_zb_device = self.get_iattr_value(item.conf, 'tasmota_zb_device')
tasmota_zb_group = self.get_iattr_value(item.conf, 'tasmota_zb_group')
tasmota_zb_attr = self.get_iattr_value(item.conf, 'tasmota_zb_attr')
tasmota_zb_cluster = self.get_iattr_value(item.conf, 'tasmota_zb_cluster')
tasmota_zb_attr = tasmota_zb_attr.lower() if tasmota_zb_attr else None
# handle tasmota_admin
if tasmota_admin:
if tasmota_admin == 'delete_retained_messages' and bool(item()):
self.clear_retained_messages()
item(False, self.get_shortname())
# handle tasmota_attr
elif tasmota_attr and tasmota_attr in self.TASMOTA_ATTR_R_W:
self.logger.info(f"update_item: {item.id()}, item has been changed in SmartHomeNG outside of this plugin in {caller} with value {item()}")
value = item()
link = {
# 'attribute': (detail, data_type, bool_values, min_value, max_value)
'relay': (f'Power', bool, ['OFF', 'ON'], None, None),
'hsb': ('HsbColor', list, None, None, None),
'white': ('White', int, None, 0, 120),
'ct': ('CT', int, None, 153, 500),
'rf_send': ('Backlog', dict, None, None, None),
'rf_key_send': (f'RfKey', int, None, 1, 16),
'rf_key': (f'RfKey', bool, None, None, None),
'zb_permit_join': ('ZbPermitJoin', bool, ['0', '1'], None, None),
'zb_forget': ('ZbForget', bool, ['0', '1'], None, None),
'zb_ping': ('ZbPing', bool, ['0', '1'], None, None),
}
if tasmota_attr not in link:
return
(detail, data_type, bool_values, min_value, max_value) = link[tasmota_attr]
# check data type
if not isinstance(value, data_type):
self.logger.warning(f"update_item: type of value {type(value)} for tasmota_attr={tasmota_attr} to be published, does not fit with expected type '{data_type}'. Abort publishing.")
return
# check and correct if value is in allowed range
if min_value and value < min_value:
self.logger.info(f'Commanded value for {tasmota_attr} below min value; set to allowed min value.')
value = min_value
elif max_value and value > max_value:
self.logger.info(f'Commanded value for {tasmota_attr} above max value; set to allowed max value.')
value = max_value
# do tasmota_attr specific checks and adaptations
if tasmota_attr == 'relay':
detail = f"{detail}{tasmota_relay}" if tasmota_relay > '1' else detail
elif tasmota_attr == 'hsb':
if not len(value) == 3:
return
new_value = f"{value[0]},{value[1]},{value[2]}"
value = new_value
elif tasmota_attr == 'rf_send':
# Input: {'RfSync': 12220, 'RfLow': 440, 'RfHigh': 1210, 'RfCode':'#F06104'} / Output: "RfSync 12220; RfLow 440; RfHigh 1210; RfCode #F06104"
rf_cmd = {k.lower(): v for k, v in value.items()}
if all(k in rf_cmd for k in [x.lower() for x in self.RF_MSG]):
value = f"RfSync {value['rfsync']}; RfLow {value['rflow']}; RfHigh {value['rfhigh']}; RfCode #{value['rfcode']}"
else:
self.logger.debug(f"update_item: rf_send received but not with correct content; expected content is: {'RfSync': 12220, 'RfLow': 440, 'RfHigh': 1210, 'RfCode':'#F06104'}")
return
elif tasmota_attr == 'rf_key_send':
detail = f"{detail}{value}"
value = 1
elif tasmota_attr == 'rf_key':
if not tasmota_rf_details:
self.logger.warning(f"tasmota_rf_details not specified, no action taken.")
return
if tasmota_rf_details and '=' in tasmota_rf_details:
tasmota_rf_details, tasmota_rf_key_param = tasmota_rf_details.split('=')
detail = f"{detail}{tasmota_rf_details}"
value = 1
elif tasmota_attr == 'zb_forget':
if value not in self.tasmota_zigbee_devices:
self.logger.error(f"Device {value} not known by plugin, no action taken.")
return
elif tasmota_attr == 'zb_ping':
if value not in self.tasmota_zigbee_devices:
self.logger.error(f"Device {value} not known by plugin, no action taken.")
return
if value is not None:
self.publish_tasmota_topic('cmnd', tasmota_topic, detail, value, item, bool_values=bool_values)
# handle tasmota_zb_attr
elif tasmota_zb_attr and tasmota_zb_attr in self.TASMOTA_ZB_ATTR_R_W:
self.logger.info(f"update_item: item={item.id()} with tasmota_zb_attr={tasmota_zb_attr} has been changed from {caller} with value={item()}")
self.logger.info(f"update_item: tasmota_zb_device={tasmota_zb_device}; tasmota_zb_group={tasmota_zb_group}")
if tasmota_zb_device is None and tasmota_zb_group is None:
return
value = int(item())
detail = 'ZbSend'
link = {
# 'attribute': (send_cmd, bool_values, min_value, max_value, cluster, convert)
'power': ('Power', ['OFF', 'ON'], None, None, '0x0006', None),
'dimmer': ('Dimmer', None, 0, 100, '0x0008', _100_to_254),
'hue': ('Hue', None, 0, 360, '0x0300', _360_to_254),
'sat': ('Sat', None, 0, 100, '0x0300', _100_to_254),
'ct': ('CT', None, 150, 500, '0x0300', None),
'ct_k': ('CT', None, 2000, 6700, '0x0300', _kelvin_to_mired),
}
if tasmota_zb_attr not in link:
return
(send_cmd, bool_values, min_value, max_value, cluster, convert) = link[tasmota_zb_attr]
# check and correct if value is in allowed range
if min_value and value < min_value:
self.logger.info(f'Commanded value for {tasmota_zb_attr} below min value; set to allowed min value.')
value = min_value
elif max_value and value > max_value:
self.logger.info(f'Commanded value for {tasmota_zb_attr} above max value; set to allowed max value.')
value = max_value
# Konvertiere Wert
if convert:
value = convert(value)
# build payload
payload = {'Device': tasmota_zb_device} if tasmota_zb_device else {'group': tasmota_zb_group}
payload['Send'] = {send_cmd: value}
if tasmota_zb_cluster:
payload['Cluster'] = cluster
self.logger.debug(f"payload={payload}")
# publish command
self.publish_tasmota_topic('cmnd', tasmota_topic, detail, payload, item, bool_values=bool_values)
else:
self.logger.warning(f"update_item: {item.id()}, trying to change item in SmartHomeNG that is read only in tasmota device (by {caller})")
############################################################
# Callbacks
############################################################
# ToDo: 2023-01-20 17:21:04 ERROR modules.mqtt _on_log: Caught exception in on_message: 'ip'
def on_mqtt_discovery_message(self, topic: str, payload: dict, qos: int = None, retain: bool = None) -> None:
"""
Callback function to handle received discovery messages
:param topic: MQTT topic
:param payload: MQTT message payload
:param qos: qos for this message (optional)
:param retain: retain flag for this message (optional)
"""
self._handle_retained_message(topic, retain)
try:
(tasmota, discovery, device_id, msg_type) = topic.split('/')
self.logger.info(f"on_mqtt_discovery_message: device_id={device_id}, type={msg_type}, payload={payload}")
except Exception as e:
self.logger.error(f"received topic {topic} is not in correct format. Error was: {e}")
else:
if msg_type == 'config':
"""
device_id = 2CF432CC2FC5
payload =
{
'ip': '192.168.2.33', // IP address
'dn': 'NXSM200_01', // Device name
'fn': ['NXSM200_01', None, None, None, None, None, None, None], // List of friendly names
'hn': 'NXSM200-01-4037', // Hostname
'mac': '2CF432CC2FC5', // MAC Adresse ohne :
'md': 'NXSM200', // Module
'ty': 0, // Tuya
'if': 0, // ifan
'ofln': 'Offline', // LWT-offline
'onln': 'Online', // LWT-online
'state': ['OFF', 'ON', 'TOGGLE', 'HOLD'], // StateText[0..3]
'sw': '12.1.1', // Firmware Version
't': 'NXSM200_01', // Topic
'ft': '%prefix%/%topic%/', // Full Topic
'tp': ['cmnd', 'stat', 'tele'], // Topic [SUB_PREFIX, PUB_PREFIX, PUB_PREFIX2]
'rl': [1, 0, 0, 0, 0, 0, 0, 0], // Relays, 0: disabled, 1: relay, 2.. future extension (fan, shutter?)
'swc': [-1, -1, -1, -1, -1, -1, -1, -1], // SwitchMode
'swn': [None, None, None, None, None, None, None, None], // SwitchName
'btn': [0, 0, 0, 0, 0, 0, 0, 0], // Buttons
'so': {'4': 0, '11': 0, '13': 0, '17': 0, '20': 0, '30': 0, '68': 0, '73': 0, '82': 0, '114': 0, '117': 0}, // SetOption needed by HA to map Tasmota devices to HA entities and triggers
'lk': 0, // ctrgb
'lt_st': 0, // Light subtype
'sho': [0, 0, 0, 0],
'sht': [[0, 0, 48], [0, 0, 46], [0, 0, 110], [0, 0, 108]],
'ver': 1 // Discovery protocol version
}
"""
tasmota_topic = payload['t']
if tasmota_topic:
device_name = payload['dn']
self.logger.info(f"Discovered Tasmota Device with topic={tasmota_topic} and device_name={device_name}")
# if device is unknown, add it to dict
if tasmota_topic not in self.tasmota_devices:
self.logger.info(f"New device based on Discovery Message found.")
self._add_new_device_to_tasmota_devices(tasmota_topic)
# process decoding message and set device to status 'discovered'
self.tasmota_devices[tasmota_topic]['ip'] = payload['ip']
self.tasmota_devices[tasmota_topic]['friendly_name'] = payload['fn'][0]
self.tasmota_devices[tasmota_topic]['fw_ver'] = payload['sw']
self.tasmota_devices[tasmota_topic]['device_id'] = device_id
self.tasmota_devices[tasmota_topic]['module'] = payload['md']
self.tasmota_devices[tasmota_topic]['mac'] = ':'.join(device_id[i:i + 2] for i in range(0, 12, 2))
self.tasmota_devices[tasmota_topic]['discovery_config'] = self._rename_discovery_keys(payload)
self.tasmota_devices[tasmota_topic]['status'] = 'discovered'
# start device interview
self._interview_device(tasmota_topic)
if payload['ft'] != self.full_topic:
self.logger.warning(f"Device {device_name} discovered, but FullTopic of device does not match plugin setting!")
# if zigbee bridge, process those
if 'zigbee_bridge' in device_name.lower():
self.logger.info(f"Zigbee_Bridge discovered")
self.tasmota_devices[tasmota_topic]['zigbee']['status'] = 'discovered'
self._configure_zigbee_bridge_settings(tasmota_topic)
self._discover_zigbee_bridge_devices(tasmota_topic)
elif msg_type == 'sensors':
"""
device_id = 2CF432CC2FC5
payload = {'sn': {'Time': '2022-11-19T13:35:59',
'ENERGY': {'TotalStartTime': '2019-12-23T17:02:03', 'Total': 85.314, 'Yesterday': 0.0,
'Today': 0.0, 'Power': 0, 'ApparentPower': 0, 'ReactivePower': 0, 'Factor': 0.0,
'Voltage': 0, 'Current': 0.0}}, 'ver': 1}
"""
# get payload with Sensor information
sensor_payload = payload['sn']
if 'Time' in sensor_payload:
sensor_payload.pop('Time')
# find matching tasmota_topic
tasmota_topic = None
for entry in self.tasmota_devices:
if self.tasmota_devices[entry].get('device_id') == device_id:
tasmota_topic = entry
break
# hand over sensor information payload for parsing
if sensor_payload and tasmota_topic:
self.logger.info(f"Discovered Tasmota Device with topic={tasmota_topic} and SensorInformation")
self._handle_sensor(tasmota_topic, '', sensor_payload)
def on_mqtt_lwt_message(self, topic: str, payload: bool, qos: int = None, retain: bool = None) -> None:
"""
Callback function to handle received lwt messages
:param topic: MQTT topic
:param payload: MQTT message payload
:param qos: qos for this message (optional)
:param retain: retain flag for this message (optional)
"""
self._handle_retained_message(topic, retain)
try:
(topic_type, tasmota_topic, info_topic) = topic.split('/')
except Exception as e:
self.logger.error(f"received topic {topic} is not in correct format. Error was: {e}")
else:
self.logger.info(f"Received LWT Message for {tasmota_topic} with value={payload} and retain={retain}")
if payload:
if tasmota_topic not in self.tasmota_devices:
self.logger.debug(f"New online device based on LWT Message discovered.")
self._handle_new_discovered_device(tasmota_topic)
self.tasmota_devices[tasmota_topic]['online_timeout'] = datetime.now() + timedelta(seconds=self.telemetry_period + 5)
if tasmota_topic in self.tasmota_devices:
self.tasmota_devices[tasmota_topic]['online'] = payload
self._set_item_value(tasmota_topic, 'item_online', payload, info_topic)
def on_mqtt_status0_message(self, topic: str, payload: dict, qos: int = None, retain: bool = None) -> None:
"""
Callback function to handle received messages
:param topic: MQTT topic
:param payload: MQTT message payload
:param qos: qos for this message
:param retain: retain flag for this message
"""
"""
Example payload
payload = {'Status': {'Module': 75, 'DeviceName': 'ZIGBEE_Bridge01', 'FriendlyName': ['SONOFF_ZB1'],
'Topic': 'SONOFF_ZB1', 'ButtonTopic': '0', 'Power': 0, 'PowerOnState': 3, 'LedState': 1,
'LedMask': 'FFFF', 'SaveData': 1, 'SaveState': 1, 'SwitchTopic': '0',
'SwitchMode': [0, 0, 0, 0, 0, 0, 0, 0], 'ButtonRetain': 0, 'SwitchRetain': 0,
'SensorRetain': 0, 'PowerRetain': 0, 'InfoRetain': 0, 'StateRetain': 0},
'StatusPRM': {'Baudrate': 115200, 'SerialConfig': '8N1', 'GroupTopic': 'tasmotas',
'OtaUrl': 'http://ota.tasmota.com/tasmota/release/tasmota-zbbridge.bin.gz',
'RestartReason': 'Software/System restart', 'Uptime': '0T23:18:30',
'StartupUTC': '2022-11-19T12:10:15', 'Sleep': 50, 'CfgHolder': 4617, 'BootCount': 116,
'BCResetTime': '2021-04-28T08:32:10', 'SaveCount': 160, 'SaveAddress': '1FB000'},
'StatusFWR': {'Version': '12.1.1(zbbridge)', 'BuildDateTime': '2022-08-25T11:37:17', 'Boot': 31,
'Core': '2_7_4_9', 'SDK': '2.2.2-dev(38a443e)', 'CpuFrequency': 160,
'Hardware': 'ESP8266EX', 'CR': '372/699'},
'StatusLOG': {'SerialLog': 0, 'WebLog': 2, 'MqttLog': 0, 'SysLog': 0, 'LogHost': '', 'LogPort': 514,
'SSId': ['WLAN-Access', ''], 'TelePeriod': 300, 'Resolution': '558180C0',
'SetOption': ['00008009', '2805C80001000600003C5A0A002800000000', '00000080',
'40046002', '00004810', '00000000']},
'StatusMEM': {'ProgramSize': 685, 'Free': 1104, 'Heap': 25, 'ProgramFlashSize': 2048,
'FlashSize': 2048, 'FlashChipId': '1540A1', 'FlashFrequency': 40, 'FlashMode': 3,
'Features': ['00000809', '0F1007C6', '04400001', '00000003', '00000000', '00000000',
'00020080', '00200000', '04000000', '00000000'],
'Drivers': '1,2,4,7,9,10,12,20,23,38,41,50,62', 'Sensors': '1'},
'StatusNET': {'Hostname': 'SONOFF-ZB1-6926', 'IPAddress': '192.168.2.24', 'Gateway': '192.168.2.1',
'Subnetmask': '255.255.255.0', 'DNSServer1': '192.168.2.1', 'DNSServer2': '0.0.0.0',
'Mac': '84:CC:A8:AA:1B:0E', 'Webserver': 2, 'HTTP_API': 1, 'WifiConfig': 0,
'WifiPower': 17.0},
'StatusMQT': {'MqttHost': '192.168.2.12', 'MqttPort': 1883, 'MqttClientMask': 'DVES_%06X',
'MqttClient': 'DVES_AA1B0E', 'MqttUser': 'DVES_USER', 'MqttCount': 1,
'MAX_PACKET_SIZE': 1200, 'KEEPALIVE': 30, 'SOCKET_TIMEOUT': 4},
'StatusTIM': {'UTC': '2022-11-20T11:28:45', 'Local': '2022-11-20T12:28:45',
'StartDST': '2022-03-27T02:00:00', 'EndDST': '2022-10-30T03:00:00',
'Timezone': '+01:00', 'Sunrise': '08:07', 'Sunset': '17:04'},
'StatusSNS': {'Time': '2022-11-20T12:28:45'},
'StatusSTS': {'Time': '2022-11-20T12:28:45', 'Uptime': '0T23:18:30', 'UptimeSec': 83910, 'Vcc': 3.41,
'Heap': 24, 'SleepMode': 'Dynamic', 'Sleep': 50, 'LoadAvg': 19, 'MqttCount': 1,
'Wifi': {'AP': 1, 'SSId': 'WLAN-Access', 'BSSId': '38:10:D5:15:87:69', 'Channel': 1,
'Mode': '11n', 'RSSI': 50, 'Signal': -75, 'LinkCount': 1,
'Downtime': '0T00:00:03'}}}
"""
self._handle_retained_message(topic, retain)
try:
(topic_type, tasmota_topic, info_topic) = topic.split('/')
self.logger.info(f"on_mqtt_status0_message: topic_type={topic_type}, tasmota_topic={tasmota_topic}, info_topic={info_topic}, payload={payload}")
except Exception as e:
self.logger.error(f"received topic {topic} is not in correct format. Error was: {e}")
else:
self.logger.info(f"Received Status0 Message for {tasmota_topic} with value={payload} and retain={retain}")
self.tasmota_devices[tasmota_topic]['status'] = 'interviewed'
# handle teleperiod
self._handle_teleperiod(tasmota_topic, payload['StatusLOG'])
if self.tasmota_devices[tasmota_topic]['status'] != 'interviewed':
if self.tasmota_devices[tasmota_topic]['status'] != 'discovered':
# friendly name
self.tasmota_devices[tasmota_topic]['friendly_name'] = payload['Status']['FriendlyName'][0]
# IP Address
ip = payload['StatusNET']['IPAddress']
ip_eth = payload['StatusNET'].get('Ethernet', {}).get('IPAddress')
ip = ip_eth if ip == '0.0.0.0' else None
self.tasmota_devices[tasmota_topic]['ip'] = ip
# Firmware
self.tasmota_devices[tasmota_topic]['fw_ver'] = payload['StatusFWR']['Version'].split('(')[0]
# MAC
self.tasmota_devices[tasmota_topic]['mac'] = payload['StatusNET']['Mac']
# Module No
self.tasmota_devices[tasmota_topic]['template'] = payload['Status']['Module']
# get detailed status using payload['StatusSTS']
status_sts = payload['StatusSTS']
# Handling Lights and Dimmer
if any([i in status_sts for i in self.LIGHT_MSG]):
self._handle_lights(tasmota_topic, info_topic, status_sts)
# Handling of Power
if any(item.startswith("POWER") for item in status_sts.keys()):
self._handle_power(tasmota_topic, info_topic, status_sts)
# Handling of RF messages
if any(item.startswith("Rf") for item in status_sts.keys()):
self._handle_rf(tasmota_topic, info_topic, status_sts)
# Handling of Wi-Fi
if 'Wifi' in status_sts:
self._handle_wifi(tasmota_topic, status_sts['Wifi'])
# Handling of Uptime
if 'Uptime' in status_sts:
self._handle_uptime(tasmota_topic, status_sts['Uptime'])
# Handling of UptimeSec
if 'UptimeSec' in status_sts:
self.logger.info(f"Received Message contains UptimeSec information.")
self._handle_uptime_sec(tasmota_topic, status_sts['UptimeSec'])
def on_mqtt_info_message(self, topic: str, payload: dict, qos: int = None, retain: bool = None) -> None:
"""
Callback function to handle received messages
:param topic: MQTT topic
:param payload: MQTT message payload
:param qos: qos for this message (optional)
:param retain: retain flag for this message (optional)
"""
self._handle_retained_message(topic, retain)
try:
(topic_type, tasmota_topic, info_topic) = topic.split('/')
self.logger.debug(f"on_mqtt_message: topic_type={topic_type}, tasmota_topic={tasmota_topic}, info_topic={info_topic}, payload={payload}")
except Exception as e:
self.logger.error(f"received topic {topic} is not in correct format. Error was: {e}")
else:
if info_topic == 'INFO1':
# payload={'Info1': {'Module': 'Sonoff Basic', 'Version': '11.0.0(tasmota)', 'FallbackTopic': 'cmnd/DVES_2EB8AE_fb/', 'GroupTopic': 'cmnd/tasmotas/'}}
self.logger.debug(f"Received Message decoded as INFO1 message.")
self.tasmota_devices[tasmota_topic]['fw_ver'] = payload['Info1']['Version'].split('(')[0]
self.tasmota_devices[tasmota_topic]['module_no'] = payload['Info1']['Module']
elif info_topic == 'INFO2':
# payload={'Info2': {'WebServerMode': 'Admin', 'Hostname': 'SONOFF-B1-6318', 'IPAddress': '192.168.2.25'}}
self.logger.debug(f"Received Message decoded as INFO2 message.")
self.tasmota_devices[tasmota_topic]['ip'] = payload['Info2']['IPAddress']
elif info_topic == 'INFO3':
# payload={'Info3': {'RestartReason': 'Software/System restart', 'BootCount': 1395}}
self.logger.debug(f"Received Message decoded as INFO3 message.")
restart_reason = payload['Info3']['RestartReason']
self.logger.warning(f"Device {tasmota_topic} (IP={self.tasmota_devices[tasmota_topic]['ip']}) just startet. Reason={restart_reason}")
def on_mqtt_message(self, topic: str, payload: dict, qos: int = None, retain: bool = None) -> None:
"""
Callback function to handle received messages
:param topic: MQTT topic
:param payload: MQTT message payload
:param qos: qos for this message (optional)
:param retain: retain flag for this message (optional)
"""
self._handle_retained_message(topic, retain)
try:
(topic_type, tasmota_topic, info_topic) = topic.split('/')
self.logger.info(f"on_mqtt_message: topic_type={topic_type}, tasmota_topic={tasmota_topic}, info_topic={info_topic}, payload={payload}")
except Exception as e:
self.logger.error(f"received topic {topic} is not in correct format. Error was: {e}")
else:
# handle unknown device
if tasmota_topic not in self.tasmota_devices:
self._handle_new_discovered_device(tasmota_topic)
# handle message
if isinstance(payload, dict) and info_topic in ['STATE', 'RESULT']:
# Handling of TelePeriod
if 'TelePeriod' in payload:
self.logger.info(f"Received Message decoded as teleperiod message.")
self._handle_teleperiod(tasmota_topic, payload['TelePeriod'])
elif 'Module' in payload:
self.logger.info(f"Received Message decoded as Module message.")
self._handle_module(tasmota_topic, payload['Module'])
# Handling of Light messages
elif any([i in payload for i in self.LIGHT_MSG]):
self.logger.info(f"Received Message decoded as light message.")
self._handle_lights(tasmota_topic, info_topic, payload)
# Handling of Power messages
elif any(item.startswith("POWER") for item in payload.keys()):
self.logger.info(f"Received Message decoded as power message.")
self._handle_power(tasmota_topic, info_topic, payload)
# Handling of RF messages payload={'Time': '2022-11-21T11:22:55', 'RfReceived': {'Sync': 10120, 'Low': 330, 'High': 980, 'Data': '3602B8', 'RfKey': 'None'}}
elif 'RfReceived' in payload:
self.logger.info(f"Received Message decoded as RF message.")
self._handle_rf(tasmota_topic, info_topic, payload['RfReceived'])
# Handling of Setting messages
elif next(iter(payload)).startswith("SetOption"):
# elif any(item.startswith("SetOption") for item in payload.keys()):
self.logger.info(f"Received Message decoded as Tasmota Setting message.")
self._handle_setting(tasmota_topic, payload)
# Handling of Zigbee Bridge Config messages
elif 'ZbConfig' in payload:
self.logger.info(f"Received Message decoded as Zigbee Config message.")
self._handle_zbconfig(tasmota_topic, payload['ZbConfig'])
# Handling of Zigbee Bridge Status messages
elif any(item.startswith("ZbStatus") for item in payload.keys()):
self.logger.info(f"Received Message decoded as Zigbee ZbStatus message.")
self._handle_zbstatus(tasmota_topic, payload)
# Handling of Wi-Fi
if 'Wifi' in payload:
self.logger.info(f"Received Message contains Wifi information.")
self._handle_wifi(tasmota_topic, payload['Wifi'])
# Handling of Uptime
if 'Uptime' in payload:
self.logger.info(f"Received Message contains Uptime information.")
self._handle_uptime(tasmota_topic, payload['Uptime'])
# Handling of UptimeSec
if 'UptimeSec' in payload:
self.logger.info(f"Received Message contains UptimeSec information.")
self._handle_uptime_sec(tasmota_topic, payload['UptimeSec'])
elif isinstance(payload, dict) and info_topic == 'SENSOR':
self.logger.info(f"Received Message contains sensor information.")
self._handle_sensor(tasmota_topic, info_topic, payload)
else:
self.logger.warning(f"Received Message '{payload}' not handled within plugin.")
# setting new online-timeout
self.tasmota_devices[tasmota_topic]['online_timeout'] = datetime.now() + timedelta(seconds=self.telemetry_period + 5)
# setting online_item to True
self._set_item_value(tasmota_topic, 'item_online', True, info_topic)
def on_mqtt_power_message(self, topic: str, payload: dict, qos: int = None, retain: bool = None) -> None:
"""
Callback function to handle received messages
:param topic: MQTT topic
:param payload: MQTT message payload
:param qos: qos for this message (optional)
:param retain: retain flag for this message (optional)
"""
self._handle_retained_message(topic, retain)
# check for retained message and handle it
if bool(retain):
if topic not in self.topics_of_retained_messages:
self.topics_of_retained_messages.append(topic)
else:
if topic in self.topics_of_retained_messages:
self.topics_of_retained_messages.remove(topic)
# handle incoming message
try:
(topic_type, tasmota_topic, info_topic) = topic.split('/')
self.logger.info(f"on_mqtt_power_message: topic_type={topic_type}, tasmota_topic={tasmota_topic}, info_topic={info_topic}, payload={payload}")
except Exception as e:
self.logger.error(f"received topic {topic} is not in correct format. Error was: {e}")
else:
device = self.tasmota_devices.get(tasmota_topic, None)
if device:
if info_topic.startswith('POWER'):
tasmota_relay = str(info_topic[5:])
tasmota_relay = '1' if not tasmota_relay else None
item_relay = f'item_relay{tasmota_relay}'
self._set_item_value(tasmota_topic, item_relay, payload == 'ON', info_topic)
self.tasmota_devices[tasmota_topic]['relais'][info_topic] = payload
############################################################
# Parse detailed messages
############################################################
def _handle_sensor(self, device: str, function: str, payload: dict) -> None:
"""
:param device:
:param function:
:param payload:
:return:
"""
# Handling of Zigbee Device Messages
if 'ZbReceived' in payload:
self.logger.info(f"Received Message decoded as Zigbee Sensor message.")
self._handle_sensor_zigbee(device, function, payload['ZbReceived'])
# Handling of Energy Sensors
elif 'ENERGY' in payload:
self.logger.info(f"Received Message decoded as Energy Sensor message.")
self._handle_sensor_energy(device, function, payload['ENERGY'])
# Handling of Environmental Sensors
elif any([i in payload for i in self.ENV_SENSOR]):
self._handle_sensor_env(device, function, payload)
# Handling of Analog Sensors
elif 'ANALOG' in payload:
self.logger.info(f"Received Message decoded as ANALOG Sensor message.")
self._handle_sensor_analog(device, function, payload['ANALOG'])
# Handling of Sensors of ESP32
elif 'ESP32' in payload:
self.logger.info(f"Received Message decoded as ESP32 Sensor message.")
self._handle_sensor_esp32(device, function, payload['ESP32'])
# Handling of any other Sensor e.g. all SML devices
else:
if len(payload) == 2 and isinstance(payload[list(payload.keys())[1]], dict): # wenn payload 2 Einträge und der zweite Eintrag vom Typ dict
self.logger.info(f"Received Message decoded as other Sensor message (e.g. smartmeter).")
sensor = list(payload.keys())[1]
self._handle_sensor_other(device, sensor, function, payload[sensor])
def _handle_sensor_zigbee(self, device: str, function: str, payload: dict) -> None:
"""
Handles Zigbee Sensor information and set items
:param payload: payload containing zigbee sensor infos
:return:
"""
"""
payload = {'Fenster_01': {'Device': '0xD4F3', 'Name': 'Fenster_01', 'Contact': 0, 'Endpoint': 1, 'LinkQuality': 92}}
"""
# self.logger.debug(f"_handle_sensor_zigbee: {device=}, {function=}, {payload=}")
for zigbee_device in payload:
if zigbee_device != '0x0000' and zigbee_device not in self.tasmota_zigbee_devices:
self.logger.info(f"New Zigbee Device '{zigbee_device}'based on {function}-Message from {device} discovered")
self.tasmota_zigbee_devices[zigbee_device] = {}
# Make all keys of Zigbee-Device Payload Dict lowercase to match itemtype from parse_item
zigbee_device_dict = {k.lower(): v for k, v in payload[zigbee_device].items()}
# Korrigieren der Werte für (HSB) Dimmer (0-254 -> 0-100), Hue(0-254 -> 0-360), Saturation (0-254 -> 0-100)
if 'dimmer' in zigbee_device_dict:
zigbee_device_dict.update({'dimmer': _254_to_100(zigbee_device_dict['dimmer'])})
if 'sat' in zigbee_device_dict:
zigbee_device_dict.update({'sat': _254_to_100(zigbee_device_dict['sat'])})
if 'hue' in zigbee_device_dict:
zigbee_device_dict.update({'hue': _254_to_360(zigbee_device_dict['hue'])})
if 'ct' in zigbee_device_dict:
zigbee_device_dict['ct_k'] = _mired_to_kelvin(zigbee_device_dict['ct'])
# Korrektur des LastSeenEpoch von Timestamp zu datetime
if 'lastseenepoch' in zigbee_device_dict:
zigbee_device_dict.update({'lastseenepoch': datetime.fromtimestamp(zigbee_device_dict['lastseenepoch'])})
if 'batterylastseenepoch' in zigbee_device_dict:
zigbee_device_dict.update({'batterylastseenepoch': datetime.fromtimestamp(zigbee_device_dict['batterylastseenepoch'])})
# Udpate des Sub-Dicts
self.tasmota_zigbee_devices[zigbee_device].update(zigbee_device_dict)
# Iterate over payload and set corresponding items
for element in zigbee_device_dict:
itemtype = f"item_{zigbee_device}.{element.lower()}"
value = zigbee_device_dict[element]
self._set_item_value(device, itemtype, value, function)
def _handle_sensor_energy(self, device: str, function: str, energy: dict):
"""
Handle Energy Sensor Information
:param device:
:param energy:
:param function:
"""
if 'ENERGY' not in self.tasmota_devices[device]['sensors']:
self.tasmota_devices[device]['sensors']['ENERGY'] = {}
self.tasmota_devices[device]['sensors']['ENERGY']['period'] = energy.get('Period', None)
for key in self.ENERGY_SENSOR_KEYS:
if key in energy:
self.tasmota_devices[device]['sensors']['ENERGY'][key.lower()] = energy[key]
self._set_item_value(device, self.ENERGY_SENSOR_KEYS[key], energy[key], function)
def _handle_sensor_env(self, device: str, function: str, payload: dict):
"""
Handle Environmental Sensor Information
:param device:
:param function:
:param payload:
"""
for sensor in self.ENV_SENSOR:
data = payload.get(sensor)
if data and isinstance(data, dict):
self.logger.debug(f"Received Message decoded as {sensor} Sensor message.")
if sensor not in self.tasmota_devices[device]['sensors']:
self.tasmota_devices[device]['sensors'][sensor] = {}
for key in self.ENV_SENSOR_KEYS:
if key in data:
self.tasmota_devices[device]['sensors'][sensor][key.lower()] = data[key]
self._set_item_value(device, self.ENV_SENSOR_KEYS[key], data[key], function)
def _handle_sensor_analog(self, device: str, function: str, analog: dict):
"""
Handle Analog Sensor Information
:param device:
:param function:
:param analog:
"""
if 'ANALOG' not in self.tasmota_devices[device]['sensors']:
self.tasmota_devices[device]['sensors']['ANALOG'] = {}
for key in self.ANALOG_SENSOR_KEYS:
if key in analog:
self.tasmota_devices[device]['sensors']['ANALOG'][key.lower()] = analog[key]