Skip to content

Commit 4d7e286

Browse files
committed
1 parent 8c307e6 commit 4d7e286

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

circutpythonMQTT/code.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import time
1111
import adafruit_minimqtt.adafruit_minimqtt as MQTT
1212

13+
#https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/blob/main/examples/native_networking/minimqtt_adafruitio_native_networking.py
1314

1415
#https://stackoverflow.com/questions/1969240/mapping-a-range-of-values-to-another
1516
def translate(sensor_val, in_from, in_to, out_from, out_to):
@@ -32,8 +33,6 @@ def subscribe(mqtt_client, userdata, topic, granted_qos):
3233
print("Subscribed to {0} with QOS level {1}".format(topic, granted_qos))
3334

3435
def message(client, topic, message):
35-
if not("envoy_20223xxxxxxxx_current_power_" in topic):
36-
return
3736
print("New message on topic {0}: {1}".format(topic, message))
3837
try:
3938
value = int(message)
@@ -68,9 +67,7 @@ def message(client, topic, message):
6867
mqtt_client.on_subscribe = subscribe
6968
mqtt_client.on_message = message
7069

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)]
7471

7572
try:
7673
mqtt_client.connect()
@@ -80,6 +77,6 @@ def message(client, topic, message):
8077

8178
while True:
8279
try:
83-
mqtt_client.loop()
80+
mqtt_client.loop(timeout=1)
8481
except:
8582
supervisor.reload()

0 commit comments

Comments
 (0)