10
10
import time
11
11
import adafruit_minimqtt .adafruit_minimqtt as MQTT
12
12
13
+ #https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/blob/main/examples/native_networking/minimqtt_adafruitio_native_networking.py
13
14
14
15
#https://stackoverflow.com/questions/1969240/mapping-a-range-of-values-to-another
15
16
def translate (sensor_val , in_from , in_to , out_from , out_to ):
@@ -32,8 +33,6 @@ def subscribe(mqtt_client, userdata, topic, granted_qos):
32
33
print ("Subscribed to {0} with QOS level {1}" .format (topic , granted_qos ))
33
34
34
35
def message (client , topic , message ):
35
- if not ("envoy_20223xxxxxxxx_current_power_" in topic ):
36
- return
37
36
print ("New message on topic {0}: {1}" .format (topic , message ))
38
37
try :
39
38
value = int (message )
@@ -68,9 +67,7 @@ def message(client, topic, message):
68
67
mqtt_client .on_subscribe = subscribe
69
68
mqtt_client .on_message = message
70
69
71
- # long topic strings cause problems so we will just subscribe to _all_ the sensor states and filter them out later.
72
- # https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/issues/160
73
- topics = [("homeassistant/sensor/+/state" ,0 )]
70
+ topics = [("homeassistant/sensor/envoy_2022xxxxxxxx_current_power_production/state" ,0 ),("homeassistant/sensor/envoy_2022xxxxxxxx_current_power_consumption/state" ,0 )]
74
71
75
72
try :
76
73
mqtt_client .connect ()
@@ -80,6 +77,6 @@ def message(client, topic, message):
80
77
81
78
while True :
82
79
try :
83
- mqtt_client .loop ()
80
+ mqtt_client .loop (timeout = 1 )
84
81
except :
85
82
supervisor .reload ()
0 commit comments