Giter Site home page Giter Site logo

plantgateway's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plantgateway's Issues

Pi Zero W | [Errno -3] Temporary failure in name resolution

Thanks for making this. Just tried this tonight but application won't start.

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install python3-pip build-essential libglib2.0-dev libyaml-dev (All OK)
  • sudo pip3 install --upgrade plantgateway
pi@pi-presencedown:~ $ plantgateway
Traceback (most recent call last):
  File "/usr/local/bin/plantgateway", line 37, in <module>
    main()
  File "/usr/local/bin/plantgateway", line 24, in main
    pg = PlantGateway()
  File "/usr/local/lib/python3.5/dist-packages/plantgw/__init__.py", line 130, in __init__
    self._start_client()
  File "/usr/local/lib/python3.5/dist-packages/plantgw/__init__.py", line 157, in _start_client
    self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 839, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 962, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.5/socket.py", line 694, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 733, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

What does that error mean?
Do you need http:// for MQTT address or just IP?

Release Notes

What's new in 0.7.0 respectivly MiFlora 0.6? Do I need to update my sensors for that?

Could you add some realese notes to the readme file?

__init__() takes 2 positional arguments but 3 were given

Wed, 09 Oct 2019 11:22:21 INFO PlantGateway version 0.6.2
Wed, 09 Oct 2019 11:22:21 INFO loaded config file from /root/.plantgw.yaml
Wed, 09 Oct 2019 11:22:21 INFO Getting data from sensor myplant
Wed, 09 Oct 2019 11:22:21 ERROR could not read data from 11:22:33:44:55:66 (myplant) with reason: init() takes 2 positional arguments but 3 were given
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 263, in process_all
self.process_mac(sensor)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 239, in process_mac
poller = MiFloraPoller(sensor_config.mac, BluepyBackend)
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 37, in init
self._bt_interface = BluetoothInterface(backend, adapter)
TypeError: init() takes 2 positional arguments but 3 were given
could not read data from 11:22:33:44:55:66 (myplant) with reason: init() takes 2 positional arguments but 3 were given

Cannot read data from my sensors

Hi,
I installed plantgateway on a Pi Zero. Then I run plantgateway it seems to work and everything is updated. Home Assistant shows all data. Perfekt. I setup a cronjob to run plantgateway every hour so that HA gets an update once per hour.

However when I look in HA it show the initial data and then nothing. Last update 15h ago or so.

I looked into the logs and for all 3 sensors in the room I get an exception. Actually it says “connection accepted” but then it cannot read data. The strange thing is that it was working at the beginning and I did not change anything after that except setting up the cronjob. Even when I run plantgateway manually now again it also throws the error “Cannot read data from....”

Here is an excerpt from the log (I replaced the real MAC address with XX:XX:XX:XX:XX). It is a bit beyond my skills to make sense of that but hopefully some of you can.

Sun, 15 Nov 2020 01:04:20 INFO MQTT connection returned result: Connection Accepted.
Sun, 15 Nov 2020 01:04:21 INFO MQTT connection returned result: Connection Accepted.
Sun, 15 Nov 2020 01:04:22 INFO MQTT connection returned result: Connection Accepted.
Sun, 15 Nov 2020 01:04:23 INFO MQTT connection returned result: Connection Accepted.
Sun, 15 Nov 2020 01:04:24 INFO MQTT connection returned result: Connection Accepted.
Sun, 15 Nov 2020 01:04:25 ERROR could not read data from XX:XX:XX:XX:XX:XX (Cactus LivingRoom MQTT) with reason:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 27, in _func_wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 56, in connect
self._peripheral = Peripheral(mac, iface=iface, addrType=self.address_type)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 391, in init
self._connect(deviceAddr, addrType, iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral XX:XX:XX:XX:XX, addr type: public

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 263, in process_all
self.process_mac(sensor)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 241, in process_mac
self._publish(sensor_config, poller)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 213, in _publish
MQTTAttributes.BATTERY.value: poller.parameter_value(MI_BATTERY),
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 149, in parameter_value
return self.battery_level()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 119, in battery_level
self.firmware_version()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 127, in firmware_version
with self._bt_interface.connect(self._mac) as connection:
File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 45, in enter
self._backend.connect(self._mac)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 33, in _func_wrapper
raise BluetoothBackendException() from last_error
btlewrap.base.BluetoothBackendException

Thanks very much for your help!

Missing TZ in timestamp

Add module:

pip3 install python-dateutil

Simply added/modified the following to plantgw.py:

Added import:
from dateutil.tz import tzlocal

Modified now() to include tzlocal():
MQTTAttributes.TIMESTAMP.value: datetime.now(tzlocal()).isoformat(),

data['timestamp'] = datetime.now(tzlocal()).strftime(self.config.mqtt_timestamp_format)

New Raspbian Image on RPI Zero W - no route to host [solved]

My RPI Zero W won't connect to the plant sensor. Debug logs says the following:

Tue, 16 Apr 2019 21:38:39 INFO     PlantGateway version 0.5.1
Tue, 16 Apr 2019 21:38:39 INFO     loaded config file from /root/.plantgw.yaml
Tue, 16 Apr 2019 21:38:39 INFO     Getting data from sensor myplant
Tue, 16 Apr 2019 21:38:39 ERROR    could not read data from C4:7C:8D:6A:94:48 (myplant) with reason: [Errno 113] No route to host
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 212, in process_all
    self.process_mac(sensor)
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 190, in process_mac
    self._publish(sensor_config, poller)
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 163, in _publish
    self.start_client()
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 137, in start_client
    self._start_client()
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 159, in _start_client
    self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 839, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 962, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.5/socket.py", line 712, in create_connection
    raise err
  File "/usr/lib/python3.5/socket.py", line 703, in create_connection
    sock.connect(sa)
OSError: [Errno 113] No route to host
Tue, 16 Apr 2019 21:38:39 INFO     try 1 of 6: could not process sensor(s) myplant. Waiting 1 sec for next try
Tue, 16 Apr 2019 21:38:40 INFO     Getting data from sensor myplant
Tue, 16 Apr 2019 21:38:40 ERROR    could not read data from C4:7C:8D:6A:94:48 (myplant) with reason: [Errno 113] No route to host
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 212, in process_all
    self.process_mac(sensor)
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 190, in process_mac
    self._publish(sensor_config, poller)
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 163, in _publish
    self.start_client()
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 137, in start_client
    self._start_client()
  File "/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py", line 159, in _start_client
    self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 839, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 962, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.5/socket.py", line 712, in create_connection
    raise err
  File "/usr/lib/python3.5/socket.py", line 703, in create_connection
    sock.connect(sa)
OSError: [Errno 113] No route to host

Any clue what this could be?

hcitool lescan shows the mac adres:

pi@plant-gateway:~ $ sudo hcitool lescane
LE Scan ...
00:12:6F:3D:F9:9E Beoplay S3
57:79:81:1E:7B:EF (unknown)
57:79:81:1E:7B:EF (unknown)
5B:F2:2A:EB:62:B0 (unknown)
60:63:52:59:04:32 (unknown)
70:02:FB:45:BC:CB (unknown)
70:02:FB:45:BC:CB (unknown)
00:12:6F:3D:F9:9E (unknown)
73:FD:FA:AB:B7:57 (unknown)
73:FD:FA:AB:B7:57 (unknown)
60:2D:AA:53:B2:98 (unknown)
60:2D:AA:53:B2:98 (unknown)
4B:F3:2F:0E:D4:78 (unknown)
C8:5E:32:D8:7C:2B (unknown)
C4:7C:8D:6A:94:48 (unknown)
C4:7C:8D:6A:94:48 Flower care  <==
77:01:58:D9:B9:34 (unknown)
77:01:58:D9:B9:34 (unknown)
4B:F3:2F:0E:D4:78 (unknown)

With gatttool i'm able to connect but get the following log:

root@plant-gateway:~# /usr/bin/gatttool -b C4:7C:8D:6A:94:48 -I
[C4:7C:8D:6A:94:48][LE]> connect
Attempting to connect to C4:7C:8D:6A:94:48
Connection successful
Notification handle = 0x0021 value: 00
Notification handle = 0x0021 value: 00
Notification handle = 0x0021 value: 00
[C4:7C:8D:6A:94:48][LE]>
(gatttool:17763): GLib-WARNING **: Invalid file descriptor.

Any clue what this could be?
Thank you

MQTT Autodiscover not working

There seems to be an issue with MQTT not autodiscovering the plant sensors in Homeassistant. I can see the data is coming in when subscribe to the plant topic, but no new sensors. I tried with/without trailing slash in the topic configuration, not sure if that makes a difference. Please advise?

Subscribe to miflora/schefflera_actinophylla

Message 2 received on miflora/schefflera_actinophylla at 8:25 AM: { "battery": 100, "temperature": "34.0", "brightness": 52, "moisture": 1, "conductivity": 0, "timestamp": "2020-05-16T08:24:54.718315" }

Add to the readme

Please add to the readme that also libyaml is needed/ So like this

install python 3.4 (or above) and pip
sudo apt-get install python3-pip build-essential libglib2.0-dev libyaml.dev

MQTT autodiscovery - add "force_update"

The new autodiscovery is working great.
However, I try to monitor for stale sensors and then it would be nice if the announcement included a 'force_update= true'

I solved this by adding
payload['force_update'] = True
to plantgw.py around line 300

But this should probably be configurable from .plantgw.yaml

Display

What config in Home Assistant are you using to display a plant like this ?

screenshot

With my config, I can only see "ok" or "problem" and have to click on that to see what the problem is.

Thanks !

Select bluetooth

In the config file there is an option of selecting but...
Although i have set interface 1 it still connects via the interface 0
There are no /dev/hci0 or /dev/hci1 devices
Although i see both interfaces under bluetoothctl

It's an octoprint release

Outputs 0 when connection seems bad

Hi @ChristianKuehnel!
Really appreciate your work, implementing this in openHAB was very straight forward - thanks!

I have one issue:

  • my raspi is working indoor
  • some plants are outside
  • from time to time the connection seems to be unstable
  • plantgateway then reports all values with zeroes

Is there any chance, you can build some handle to block plantgateway from sending these values?
for example the battery value cannot jump from 100 to 0% - even better: when battery was 0% the thing would not send anything!

Can I help you out with something to track this down?
log? do you have any debug preferences to activate?

Error on firmware 3.2.1

Hello,

I just received two mi flora’s with firmware 3.2.1 even though the mi home app says 3.1.9 is the newest. I have 4 mi floras on 3.1.9 and they work great. The two new ones give bluepy.py and base.py errors. And don’t update moisture and temperature.

21:12 Mon 2 Apr -11 93% 4
on, 22 Apr 2019 20:11:19 INFO Getting data from sensor Pachira_macrocarpa
on, 22 Apr 2019 20:11:28 INFO sent data to topic plantgateway/plants/pachira_macrocarpa/
on, 22 Apr 2019 20:11:28 INFO Getting data from sensor Asparagus
Mon, 22 Apr 2019 20:12:08 INFO sent data to topic plantgateway/plants/Asparagus/
on, 22 Apr 2019 20:12:08 INFO Getting data from sensor Bush_lily
exception ignored in: <bound method Bluetoothlnterf ace.del of <btlewrap.base.Bluetoothlnterface object at 0xb69a6f10>>
racetrack (most recent ca11 last) :
File "/usr/local/lib/python3.5/dist-packages/btlewrap/base.py", line 17, in del
self. _backend.disconnect()
File "/usr/local/lib/python3.5/dist-packages/btlewrap/b1uepy.py", line 26, in _ func _wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/btlewrap/b1uepy.py", line 60, in disconnect
self. _peripheral.disconnect()
A ttributeError: 'No reType' object has no attribute 'disconnect'
on, 22 Apr 2019 20:12:10 INFO sent data to topic p1antgateway/plants/Bush_lily/
on, 22 Apr 2019 20:12:10 INFO Disconnected MOTT connection
1
pi@pizerodownstairs:~ $

could not read datawith reason: [Errno 111] Connection refused RPI 3

Hi,

I try to get this working on a raspberry pi 3.
When i run plantgateway I get the following error:

could not read data from 11:22:33:44:55:66 (bla) with reason: [Errno 111] Connection refused

At first i was thinking it is a permission error but when i run it as root i got the same error.
Im using the correct bluetooth device and the mac adress is also fine.
Can you give me a hint?

Edit:
Here is the debug log:

Tue, 06 Aug 2019 08:50:12 INFO PlantGateway version 0.6.2
Tue, 06 Aug 2019 08:50:12 INFO loaded config file from /root/.plantgw.yaml
Tue, 06 Aug 2019 08:50:12 INFO Getting data from sensor siling
Tue, 06 Aug 2019 08:50:12 ERROR could not read data from C4:7C:8D:6A:02:E6 (siling) with reason: [Errno 111] Connection refused
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 263, in process_all
self.process_mac(sensor)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 240, in process_mac
self.announce_sensor(sensor_config)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 286, in announce_sensor
self.start_client()
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 183, in start_client
self._start_client()
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 205, in _start_client
self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 839, in connect
return self.reconnect()
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 962, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
Tue, 06 Aug 2019 08:50:12 INFO try 1 of 6: could not process sensor(s) siling. Waiting 1 sec for next try
Tue, 06 Aug 2019 08:50:13 INFO Getting data from sensor siling
Tue, 06 Aug 2019 08:50:13 ERROR could not read data from C4:7C:8D:6A:02:E6 (siling) with reason: [Errno 111] Connection refused
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 263, in process_all
self.process_mac(sensor)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 240, in process_mac
self.announce_sensor(sensor_config)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 286, in announce_sensor
self.start_client()
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 183, in start_client
self._start_client()
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 205, in _start_client
self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 839, in connect
return self.reconnect()
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 962, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
Tue, 06 Aug 2019 08:50:13 INFO try 2 of 6: could not process sensor(s) siling. Waiting 2 sec for next try
Tue, 06 Aug 2019 08:50:15 INFO Getting data from sensor siling
Tue, 06 Aug 2019 08:50:15 ERROR could not read data from C4:7C:8D:6A:02:E6 (siling) with reason: [Errno 111] Connection refused
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 263, in process_all
self.process_mac(sensor)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 240, in process_mac
self.announce_sensor(sensor_config)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 286, in announce_sensor
self.start_client()
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 183, in start_client
self._start_client()
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 205, in _start_client
self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 839, in connect
return self.reconnect()
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 962, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
Tue, 06 Aug 2019 08:50:15 INFO try 3 of 6: could not process sensor(s) siling. Waiting 4 sec for next try
Tue, 06 Aug 2019 08:50:19 INFO Getting data from sensor siling
Tue, 06 Aug 2019 08:50:19 ERROR could not read data from C4:7C:8D:6A:02:E6 (siling) with reason: [Errno 111] Connection refused
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 263, in process_all
self.process_mac(sensor)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 240, in process_mac
self.announce_sensor(sensor_config)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 286, in announce_sensor
self.start_client()
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 183, in start_client
self._start_client()
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 205, in _start_client
self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 839, in connect
return self.reconnect()
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 962, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
Tue, 06 Aug 2019 08:50:19 INFO try 4 of 6: could not process sensor(s) siling. Waiting 8 sec for next try

Works only after reboot of the RPI

Hi,

I have been successfully running your solution for quite some time with the flower sensors - thank you for developing this great solution.
However, for the last few days I have a strange problem.
The program runs flawless, once I have rebooted the RPi, when it runs a second time though it has problems with each and every single sensor. As it runs the first time well, I guess it does not have problems with the bluetooth interface, but also not with accessing the MQTT Server - as both work in the first run.

I am not quite sure what I am missing here and was wondering if you could have a look into this.

The log file looks as follows in the first run, when it works:

Tue, 25 May 2021 15:37:32 INFO PlantGateway version 0.7.0
Tue, 25 May 2021 15:37:32 INFO loaded config file from /home/pi/.plantgw.yaml
Tue, 25 May 2021 15:37:32 INFO Getting data from sensor liguster
Tue, 25 May 2021 15:37:32 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_battery/config
Tue, 25 May 2021 15:37:32 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_temperature/config
Tue, 25 May 2021 15:37:32 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_brightness/config
Tue, 25 May 2021 15:37:32 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_moisture/config
Tue, 25 May 2021 15:37:32 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_conductivity/config
Tue, 25 May 2021 15:37:32 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_timestamp/config
Tue, 25 May 2021 15:37:32 INFO MQTT connection returned result: Connection Accepted.
Tue, 25 May 2021 15:37:32 INFO MQTT connection returned result: Connection Accepted.
Tue, 25 May 2021 15:37:33 INFO MQTT connection returned result: Connection Accepted.
Tue, 25 May 2021 15:37:35 INFO MQTT connection returned result: Connection Accepted.
Tue, 25 May 2021 15:37:36 INFO MQTT connection returned result: Connection Accepted.
Tue, 25 May 2021 15:37:36 INFO sent data to topic miflora/liguster/
Tue, 25 May 2021 15:37:36 INFO Getting data from sensor szechuanpfeffer
Tue, 25 May 2021 15:37:36 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_battery/config
Tue, 25 May 2021 15:37:36 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_temperature/config
Tue, 25 May 2021 15:37:36 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_brightness/config
Tue, 25 May 2021 15:37:36 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_moisture/config
Tue, 25 May 2021 15:37:36 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_conductivity/config
Tue, 25 May 2021 15:37:36 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_timestamp/config
Tue, 25 May 2021 15:37:37 INFO MQTT connection returned result: Connection Accepted.
Tue, 25 May 2021 15:37:38 INFO MQTT connection returned result: Connection Accepted.
Tue, 25 May 2021 15:37:39 INFO MQTT connection returned result: Connection Accepted.
Tue, 25 May 2021 15:37:39 INFO sent data to topic miflora/szechuanpfeffer/


In the run later it looks like this:

Tue, 25 May 2021 16:47:10 INFO Getting data from sensor liguster
Tue, 25 May 2021 16:47:10 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_battery/config
Tue, 25 May 2021 16:47:10 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_temperature/config
Tue, 25 May 2021 16:47:10 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_brightness/config
Tue, 25 May 2021 16:47:10 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_moisture/config
Tue, 25 May 2021 16:47:10 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_conductivity/config
Tue, 25 May 2021 16:47:10 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA8963D3_timestamp/config
Tue, 25 May 2021 16:47:11 ERROR could not read data from 80:EA:CA:89:63:D3 (liguster) with reason:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 27, in _func_wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 56, in connect
self._peripheral = Peripheral(mac, iface=iface, addrType=self.address_type)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 391, in init
self._connect(deviceAddr, addrType, iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral 80:EA:CA:89:63:D3, addr type: public

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 263, in process_all
self.process_mac(sensor)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 241, in process_mac
self._publish(sensor_config, poller)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 213, in _publish
MQTTAttributes.BATTERY.value: poller.parameter_value(MI_BATTERY),
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 149, in parameter_value
return self.battery_level()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 119, in battery_level
self.firmware_version()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 127, in firmware_version
with self._bt_interface.connect(self._mac) as connection:
File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 45, in enter
self._backend.connect(self._mac)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 33, in _func_wrapper
raise BluetoothBackendException() from last_error
btlewrap.base.BluetoothBackendException
Tue, 25 May 2021 16:47:11 INFO Getting data from sensor szechuanpfeffer
Tue, 25 May 2021 16:47:11 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_battery/config
Tue, 25 May 2021 16:47:11 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_temperature/config
Tue, 25 May 2021 16:47:11 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_brightness/config
Tue, 25 May 2021 16:47:11 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_moisture/config
Tue, 25 May 2021 16:47:11 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_conductivity/config
Tue, 25 May 2021 16:47:11 INFO sent sensor config to topic homeassistant/sensor/plant_80EACA895D11_timestamp/config
Tue, 25 May 2021 16:47:11 ERROR could not read data from 80:EA:CA:89:5D:11 (szechuanpfeffer) with reason:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 27, in _func_wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 56, in connect
self._peripheral = Peripheral(mac, iface=iface, addrType=self.address_type)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 391, in init
self._connect(deviceAddr, addrType, iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral 80:EA:CA:89:5D:11, addr type: public

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 263, in process_all
self.process_mac(sensor)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 241, in process_mac
self._publish(sensor_config, poller)
File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 213, in _publish
MQTTAttributes.BATTERY.value: poller.parameter_value(MI_BATTERY),
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 149, in parameter_value
return self.battery_level()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 119, in battery_level
self.firmware_version()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 127, in firmware_version
with self._bt_interface.connect(self._mac) as connection:
File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 45, in enter
self._backend.connect(self._mac)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 33, in _func_wrapper
raise BluetoothBackendException() from last_error
btlewrap.base.BluetoothBackendException


I am using a Raspberry Pi 3 Model B Plus Rev 1.3 with following hw configuration:
description: ARMv7 Processor rev 4 (v7l)
product: Raspberry Pi 3 Model B Plus Rev 1.3
serial: 00000000920415c0
width: 32 bits
capabilities: smp
*-core
description: Motherboard
physical id: 0
*-cpu:0
description: CPU
product: cpu
physical id: 0
bus info: cpu@0
size: 1400MHz
capacity: 1400MHz
capabilities: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 cpufreq
*-cpu:1
description: CPU
product: cpu
physical id: 1
bus info: cpu@1
size: 1400MHz
capacity: 1400MHz
capabilities: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 cpufreq
*-cpu:2
description: CPU
product: cpu
physical id: 2
bus info: cpu@2
size: 1400MHz
capacity: 1400MHz
capabilities: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 cpufreq
*-cpu:3
description: CPU
product: cpu
physical id: 3
bus info: cpu@3
size: 1400MHz
capacity: 1400MHz
capabilities: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 cpufreq
*-memory
description: System memory
physical id: 4
size: 924MiB
*-usbhost
product: DWC OTG Controller
vendor: Linux 5.10.17-v7+ dwc_otg_hcd
physical id: 1
bus info: usb@1
logical name: usb1
version: 5.10
capabilities: usb-2.00
configuration: driver=hub slots=1 speed=480Mbit/s
*-usb
description: USB hub
product: USB 2.0 Hub
vendor: Standard Microsystems Corp.
physical id: 1
bus info: usb@1:1
version: b.b3
capabilities: usb-2.00
configuration: driver=hub maxpower=2mA slots=4 speed=480Mbit/s
*-usb
description: USB hub
product: USB 2.0 Hub
vendor: Standard Microsystems Corp.
physical id: 1
bus info: usb@1:1.1
version: b.b3
capabilities: usb-2.00
configuration: driver=hub maxpower=2mA slots=3 speed=480Mbit/s
*-usb
description: Ethernet interface
vendor: Standard Microsystems Corp.
physical id: 1
bus info: usb@1:1.1.1
logical name: eth0
version: 3.00
serial: b8:27:eb:04:15:c0
capacity: 1Gbit/s
capabilities: usb-2.10 ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=lan78xx driverversion=5.10.17-v7+ link=no maxpower=2mA multicast=yes port=MII speed=480Mbit/s
*-network
description: Wireless interface
physical id: 2
logical name: wlan0
serial: b8:27:eb:51:40:95
capabilities: ethernet physical wireless
configuration: broadcast=yes driver=brcmfmac driverversion=7.45.229 firmware=01-2dbd9d2e ip=192.168.1.184 multicast=yes wireless=IEEE 802.11

OS: Linux 5.10.17-v7+ #1414 SMP Fri Apr 30 13:18:35 BST 2021 armv7l GNU/Linux

Any idea on what I am doing wrong is highly appreciated!

Thanks a lot!

Sven

How to set retain flag

When I restart home assistant the initial values of my plant sensors are unknown.

This first paragraph here
https://www.home-assistant.io/components/sensor.mqtt/

If messages in this state_topic are published with RETAIN flag, the sensor will receive an instant update with last known value.

tells us that the retain flag has to be set to avoid this.

Is it possible to set the retain flag in the configuration file?

Connection Refused error

Hi i am getting Connection Refused.

Fri, 03 Aug 2018 22:52:36 INFO     PlantGateway version 0.5.0
Fri, 03 Aug 2018 22:52:36 INFO     loaded config file from /root/.plantgw.yaml
Fri, 03 Aug 2018 22:52:36 INFO     Getting data from sensor Achtertuin
Fri, 03 Aug 2018 22:52:36 ERROR    could not read data from C4:7C:8D:66:E8:89 (Achtertuin) with reason: [Errno 111] Connection refused
Fri, 03 Aug 2018 22:52:36 WARNING  fail_silent is set for sensor Achtertuin, so not raising an exception.

plantgw:

    - mac: C4:7C:8D:66:E8:89
      alias: Achtertuin
      fail_silent:

using latest version in Docker. Docker config:

  plantgateway:
    image: this_image:latest
    container_name: PlantGateway
    restart: always
    network_mode: host
    volumes:
      - /home/docker/plantgateway/config:/config
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro

Selecting bluetooth device

I've been using this for some time now on a Pi downstairs. However, due to the range it isn't capable of reaching plants upstairs. Upstairs I have an RPI W Zero with additional bluetooth USB stick (since the primary/onboard bluetooth is being used for constant polling).

I'd like to install Plantgateway on this pi as well and make it use the second bluetooth stick in the system. However, looking trough the config and code I couldn't find a way to tell it which device to use.

Is this possible somehow?

Question: How many devices can this support?

I'm currently using a ESPHome ESP32 (M5Stack) as a BT Proxy to connect to probes.
I know there is a limitation to how many can be connected at once.

Does using this method give a greater connection pool of probes?

Thanks

offer plantgateway on pypi

  • release plantgateway on pypi, easier to use for non-technical users
  • set up build job to build releases automatically
  • extend testing so that we can release when tests are green

Refresh

The integration worked for me.
But I have to update manually. If I want the current status of the miFlora sensors, I have to enter the command "plantgateway" every time. Shouldn't the query be made automatically every few seconds or hours?

Setting up cronjob

Everything works perfect, got all my data in Home Assistant.

However I need some help setting up the cronjob (as I have no experience in doing that).

in crontab -e I pasted this line (just for testing every minute)

*/1 * * * * plantgateway

So this should run the tool every minute but it does not

I also tried

*/1 * * * * /home/pi/plantgateway

*/1 * * * * /plantgateway

What do I do wrong?

Connection refused

I'm using the Northfifteen Connected Home Plant Monitor because I read it runs the same firmware as the Xiaomi miflora, and those have become hard to find.

I have plantgateway running on a Raspberry Pi Zero W. It seems to find my plant monitor because sudo hcitool lescan find the mac address with "Flower care" as the name.

However when I run plantgateway I get ConnectionRefusedError: [Errno 111] Connection refused

Any thoughts? Is my hardware actually compatible?

Failed to connect to peripheral

I'm trying to run Plant Gateway on a Raspberry Pi Zero W on Raspbian Lite. I installed using the pip command. I enabled debug mode and copied and pasted the tail end of my log file. I'd appreciate any advice you may have on connecting. BTW, I replaced the battery a few weeks ago and have it sitting 3 feet from the Pi. When I pop the battery out and replace it the LED on top of the Mi Flora starts flashing. Plus I got the mac address from... I forget the command (hcitool scan?). Thank you.

Here is the partial log file:
https://gist.github.com/brianhanifin/45e439b8b9b3bde3fcedcbc5876e466f

Still Active Project

Hello @ChristianKuehnel !

I'm looking to implement your plantgateway - looks very promissing and exactly what I need :)
Just wanted to make sure before I begin - is this project still active and up to date?
I'm planning to install on HomeAssistant 0.109

Kind regards from Austria

Albert

YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated

I get the following warning on execution of the plantgateway:

/usr/local/lib/python3.5/dist-packages/plantgw/plantgw.py:33: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  config = yaml.load(config_file)

The plantgateway seems 100% functional however. With debug mode on I am seeing what's below this in the logfiles. It doesn't even mention the above notification. Seems due to an update of python or something alike, I've seen similar error messages mentioned for many other projects (not related to Plant Gateway or Home Assistant) after a Google search. But I don't have the right skills to solve it unfortunately.

Fri, 17 May 2019 22:59:12 INFO     PlantGateway version 0.5.1
Fri, 17 May 2019 22:59:12 INFO     loaded config file from /home/pi/.plantgw.yaml
Fri, 17 May 2019 22:59:12 INFO     Getting data from sensor plant1
Fri, 17 May 2019 22:59:12 INFO     MQTT connection returned result: Connection Accepted.
Fri, 17 May 2019 22:59:16 DEBUG    Received result for handle 56: 64 10 32 2E 36 2E 32
Fri, 17 May 2019 22:59:16 DEBUG    Filling cache with new sensor data.
Fri, 17 May 2019 22:59:17 DEBUG    Received result for handle 53: CC 00 00 E0 01 00 00 0E 16 01 00 00 00 00 00 00
Fri, 17 May 2019 22:59:17 DEBUG    Using cache (0:00:00.003436 < 0:10:00)
Fri, 17 May 2019 22:59:17 DEBUG    Using cache (0:00:00.004423 < 0:10:00)
Fri, 17 May 2019 22:59:17 DEBUG    Using cache (0:00:00.005148 < 0:10:00)
Fri, 17 May 2019 22:59:17 DEBUG    timestamp: 2019-05-17T22:59:17.013393
Fri, 17 May 2019 22:59:17 DEBUG    moisture: 14
Fri, 17 May 2019 22:59:17 DEBUG    temperature: 20.4
Fri, 17 May 2019 22:59:17 DEBUG    conductivity: 278
Fri, 17 May 2019 22:59:17 DEBUG    battery: 100
Fri, 17 May 2019 22:59:17 DEBUG    brightness: 480
Fri, 17 May 2019 22:59:17 INFO     sent data to topic hassio/sensor/miflora/plant1/
Fri, 17 May 2019 22:59:17 INFO     Getting data from sensor plant2
Fri, 17 May 2019 22:59:30 DEBUG    Received result for handle 56: 64 15 32 2E 37 2E 30
Fri, 17 May 2019 22:59:30 DEBUG    Filling cache with new sensor data.
Fri, 17 May 2019 22:59:30 DEBUG    Received result for handle 53: 93 00 00 8E 00 00 00 06 07 00 02 3C 00 FB 34 9B
Fri, 17 May 2019 22:59:30 DEBUG    Using cache (0:00:00.003262 < 0:10:00)
Fri, 17 May 2019 22:59:30 DEBUG    Using cache (0:00:00.004256 < 0:10:00)
Fri, 17 May 2019 22:59:30 DEBUG    Using cache (0:00:00.004983 < 0:10:00)
Fri, 17 May 2019 22:59:30 DEBUG    timestamp: 2019-05-17T22:59:30.477116
Fri, 17 May 2019 22:59:30 DEBUG    moisture: 6
Fri, 17 May 2019 22:59:30 DEBUG    temperature: 14.7
Fri, 17 May 2019 22:59:30 DEBUG    conductivity: 7
Fri, 17 May 2019 22:59:30 DEBUG    battery: 100
Fri, 17 May 2019 22:59:30 DEBUG    brightness: 142
Fri, 17 May 2019 22:59:30 INFO     sent data to topic hassio/sensor/miflora/plant2/
Fri, 17 May 2019 22:59:30 INFO     Disconnected MQTT connection

YAML error

Hi,

I’ve set this up on a RPi3 but am getting this error when I run it from terminal, even when my .plantgw.yaml file is just the template from the original repo.

Any thoughts? Thank you!

Traceback (most recent call last):
  File "/usr/local/bin/plantgateway", line 37, in <module>
    main()
  File "/usr/local/bin/plantgateway", line 24, in main
    pg = PlantGateway()
  File "/usr/local/lib/python2.7/dist-packages/plantgw/__init__.py",
line 125, in __init__
    self.config = Configuration(config_file_path)
  File "/usr/local/lib/python2.7/dist-packages/plantgw/__init__.py",
line 30, in __init__
    config = yaml.load(config_file)
  File "/usr/local/lib/python2.7/dist-packages/yaml/__init__.py", line
71, in load
    return loader.get_single_data()
  File "/usr/local/lib/python2.7/dist-packages/yaml/constructor.py",
line 37, in get_single_data
    node = self.get_single_node()
  File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line
36, in get_single_node
    document = self.compose_document()
  File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line
55, in compose_document
    node = self.compose_node(None, None)
  File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line
84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line
133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/usr/local/lib/python2.7/dist-packages/yaml/composer.py", line
64, in compose_node
    if self.check_event(AliasEvent):
  File "/usr/local/lib/python2.7/dist-packages/yaml/parser.py", line
98, in check_event
    self.current_event = self.state()
  File "/usr/local/lib/python2.7/dist-packages/yaml/parser.py", line
449, in parse_block_mapping_value
    if not self.check_token(KeyToken, ValueToken, BlockEndToken):
  File "/usr/local/lib/python2.7/dist-packages/yaml/scanner.py", line
115, in check_token
    while self.need_more_tokens():
  File "/usr/local/lib/python2.7/dist-packages/yaml/scanner.py", line
149, in need_more_tokens
    self.stale_possible_simple_keys()
  File "/usr/local/lib/python2.7/dist-packages/yaml/scanner.py", line
289, in stale_possible_simple_keys
    "could not find expected ':'", self.get_mark())
yaml.scanner.ScannerError: while scanning a simple key
  in "/home/pi/.plantgw.yaml", line 10, column 1
could not find expected ':'
  in "/home/pi/.plantgw.yaml", line 12, column 1

not starting

Hi,
my plantgateway won't start, throwing the following error:

Traceback (most recent call last):
  File "/usr/local/bin/plantgateway", line 37, in <module>
    main()
  File "/usr/local/bin/plantgateway", line 24, in main
    pg = PlantGateway()
  File "/usr/local/lib/python3.5/dist-packages/plantgw/__init__.py", line 125, in __init__
    self.config = Configuration(config_file_path)
  File "/usr/local/lib/python3.5/dist-packages/plantgw/__init__.py", line 30, in __init__
    config = yaml.load(config_file)
  File "/usr/local/lib/python3.5/dist-packages/yaml/__init__.py", line 72, in load
    return loader.get_single_data()
  File "/usr/local/lib/python3.5/dist-packages/yaml/constructor.py", line 35, in get_single_data
    node = self.get_single_node()
  File "/usr/local/lib/python3.5/dist-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/usr/local/lib/python3.5/dist-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/usr/local/lib/python3.5/dist-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/local/lib/python3.5/dist-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/usr/local/lib/python3.5/dist-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/local/lib/python3.5/dist-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/usr/local/lib/python3.5/dist-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/usr/local/lib/python3.5/dist-packages/yaml/parser.py", line 428, in parse_block_mapping_key
    if self.check_token(KeyToken):
  File "/usr/local/lib/python3.5/dist-packages/yaml/scanner.py", line 115, in check_token
    while self.need_more_tokens():
  File "/usr/local/lib/python3.5/dist-packages/yaml/scanner.py", line 149, in need_more_tokens
    self.stale_possible_simple_keys()
  File "/usr/local/lib/python3.5/dist-packages/yaml/scanner.py", line 289, in stale_possible_simple_keys
    "could not find expected ':'", self.get_mark())
yaml.scanner.ScannerError: while scanning a simple key
  in "/home/pi/.plantgw.yaml", line 20, column 5
could not find expected ':'
  in "/home/pi/.plantgw.yaml", line 21, column 5

[Errno -2] Name or service not known

Hi,
When adding my sensor toe the .plantgw.yaml I seem to get every time an error:

Wed, 01 Jun 2022 12:33:26 INFO PlantGateway version 0.7.0 Wed, 01 Jun 2022 12:33:26 INFO loaded config file from /home/pi/.plantgw.yaml Wed, 01 Jun 2022 12:33:26 INFO Getting data from sensor Flower care Wed, 01 Jun 2022 12:33:26 ERROR could not read data from C4:7C:8D:66:1A:05 (Flower care) with reason: [Errno -2] Name or service not known Wed, 01 Jun 2022 12:33:26 WARNING fail_silent is set for sensor Flower care, so not raising an exception.

What's this error?

Errors on freshly installed Raspian.

Can you see what went wrong?

Traceback (most recent call last):
  File "/usr/local/bin/plantgateway", line 30, in <module>
    main()
  File "/usr/local/bin/plantgateway", line 24, in main
    pg = PlantGateway()
  File "/usr/local/lib/python3.4/dist-packages/plantgw/__init__.py", line 95, in __init__
    self._start_client()
  File "/usr/local/lib/python3.4/dist-packages/plantgw/__init__.py", line 109, in _start_client
    self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 700, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 822, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.4/socket.py", line 509, in create_connection
    raise err
  File "/usr/lib/python3.4/socket.py", line 500, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

Persistance with home assistant auto discovery

Hello 👋 first, many thanks for the plant gateway 🙇

EDIT: only works if config message has retain flag

I am not entirely sure about all my assumption. But if I get this right, it would be very much useful to add
force_update: true and or unique_id: sensor.ALIAS to the DISCOVERY_PREFIX/sensor/plant_MAC_TYPE/config payload.

If I just use autodiscovery feature in home assistant, after a restart the entities are in undefined state. After reading up on the docs if force_update: true this should do the trick.

If I configure the whole sensor with the payload of the autodiscovery pushed by plant gateway to mqtt:

- platform: mqtt
  state_topic: "plantgw/ALIAS/"
  unit_of_measurement: "%"
  value_template: "{{value_json.battery}}"
  name: ALIAD_battery
  device_class: battery
  force_update: true

This will make the entity state available right away.
What also works is defining the unique_id: sensor.ALIAS so it can leverage on the entity registry.

- platform: mqtt
  state_topic: "plantgw/ALIAS/"
  unit_of_measurement: "%"
  value_template: "{{value_json.battery}}"
  name: ALIAD_battery
  device_class: battery
  unique_id: sensor.ALIAS

Of course, I can define all of that as mqtt sensors themselves but that renders the autodiscovery feature a bit pointless, while it would be super useful.

What do you think about adding both while keeping the backwards compatibility by sending the unique_id how its auto-generated currently?

Cheers 🍻

Running on Raspberry Pi 3

What did I do wrong?

pi@raspberrypi:~ $ plantgateway 
INFO:root:loaded config file from /home/pi/.plantgw.yaml
Traceback (most recent call last):
  File "/usr/local/bin/plantgateway", line 20, in <module>
    main()
  File "/usr/local/bin/plantgateway", line 14, in main
    pg = PlantGateway()
  File "/usr/local/lib/python3.4/dist-packages/plantgw/__init__.py", line 76, in __init__
    self._start_client()
  File "/usr/local/lib/python3.4/dist-packages/plantgw/__init__.py", line 90, in _start_client
    self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 686, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 808, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.4/socket.py", line 491, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.4/socket.py", line 530, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname

hassio addon

Would be great to have this is an hassio addon.

Helper exited

Hey,

I get the following errors:

pi@raspberrypi:~ $ plantgateway
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2990>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d35a8>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2be8>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d3620>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2cb0>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d36e8>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2c60>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d35d0>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2cb0>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d3738>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2c38>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d3788>> ignored
Could not get data from 2sensor(s): Rihanna, otherplant.
pi@raspberrypi:~ $

hcitool lescan works and I can see the sensors but no go.

bluetoothctl show the following:

root@raspberrypi:/home/pi# sudo bluetoothctl
[NEW] Controller B8:27:EB:A1:25:D2 raspberrypi [default]
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:A1:25:D2 Discovering: yes
[NEW] Device C4:7C:8D:65:B9:06 C4-7C-8D-65-B9-06
[NEW] Device C4:7C:8D:65:B8:FF Flower care
[NEW] Device 04:52:C7:B0:EB:23 04-52-C7-B0-EB-23
[CHG] Device C4:7C:8D:65:B9:06 RSSI: -88
[CHG] Device C4:7C:8D:65:B9:06 Name: Flower care
[CHG] Device C4:7C:8D:65:B9:06 Alias: Flower care
[CHG] Device C4:7C:8D:65:B8:FF RSSI: -64
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Key: 0000fe95-0000-1000-8000-00805f9b34fb
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x71
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x20
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x98
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x00
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x81
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0xff
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0xb8
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x65
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x8d
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x7c
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0xc4
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x0d
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x04
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x10
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x02
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0xc7
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x00
[CHG] Device C4:7C:8D:65:B9:06 RSSI: -74
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Key: 0000fe95-0000-1000-8000-00805f9b34fb
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x71
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x20
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x98
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x00
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x27
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x06
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0xb9
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x65
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x8d
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x7c
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0xc4
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x0d
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x08
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x10
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x01
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x19
[CHG] Device C4:7C:8D:65:B8:FF RSSI: -82
[CHG] Device C4:7C:8D:65:B9:06 RSSI: -97

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.