Open andypnz opened 1 year ago
Hi,
This is a standalone program and does not depend on AppDaemon. In fact we are not using any HA python API at all. The program interacts with HASS just like zigbee2mqtt. Everything is done via mqtt.
Sorry but I don't quite understand your second question. This program sends the desired device id to HA via mqtt. On HAOS python should be preinstalled, and it should be fine to just use that installation. For MQTT there is an addon.
I chose to write a standalone program because it's easier to restart a small program than the entire HASS.
Thanks... I think I need a Tuya hub, right?
Or will this work direct to the fingerbot via RPi BT?
You don't need a Tuya Hub. The purpose of this program is to use conventional bluetooth adapters, and to work completely offline.
If you have a Tuya Hub, you can use the official HA integration.
I'm using an HP T630 from ebay which is just a generic linux box. I don't have a RPi on hand, but it should also work as a generic linux box.
Thanks for your help! I have registered with Tuya Smart Life + Tuya iot platform.... and successfully run tuya-local-key-extractor (I was able to do this within my HAOS using SSH + Web Terminal) - so I have the required keys, ID and MAC address etc
Which directory do I copy your fingerbot.py + util.py to? Are these the only files I need from your github repo?
What triggers fingerbot.py to run?
Thanks again for your help!
If you just want to integrate with HA, and don't want to bother with details like "what triggers fingerbot.py to run", my suggestion would be:
homeassistant: true
mqtt:
base_topic: homeassistant
server: mqtt://HAOS_IP_ADDRESS:1883
user: SAME_AS_IN_HAOS_MQTT_ADDON
password: SAME_AS_IN_HAOS_MQTT_ADDON
controller:
capacity: 6
devices:
'01:02:03:04:05:08':
type: tuya.fingerbot
device_id: abc123456
uuid: tuya1234567890
local_key: abc123456
down_percent: 80
python main.py --config [path-to-config.yaml]
On success it should print
bluetooth.Client.event.connect 01:02:03:04:05:08
initialized with 1 devices
(after a while; Tuya devices go to sleep very fast) bluetooth.Client.event.disconnect 01:02:03:04:05:08
And a button device should be auto discovered in HA.
Maybe I should make a video tutorial when I get the chance :)
Thanks!
I am using HAOS and I think perhaps things are not quite so straight forward? For example, 'import' is not allowed in a Python script.
Using SSH + Web terminal I first run the command
docker exec -it homeassistant bash
which gives access to the actual HA 'container'. I then have installed the dependencies, cloned the git repository, etc.
When I run python main.py --config /config/ble2mqtt/config.yaml
I get this error as below. I think I need to use appdaemon or pyscript to run main.py - but I am really not sure.....
It is running fingerbot.py as sexpect, but complaining about a bluetooth timeout.
There can be several reasons for a bluetooth timeout:
bluetoothctl connect [01:02:03:04:05:08 <- MAC of fingerbot]
outside docker?This is a plain old python program that does not really depends on HA or appdaemon or pyscript. You don't need to run it inside the HA container, and I don't know what can happen inside that container. The only thing matters is the MQTT configuration, i.e. base_topic/server/user/password.
That command gave me this response: Same response if I run it outside or inside the HA container (actually, I am not even sure if I am using the correct terminology here....)
I realized I did not have
Bluetooth:
In my configuration.yaml - so added that.... BTW, should I have 'passive scanning' ticked under the BT integration? Probably it does not effect this?
Now running python main.py --config /config/ble2mqtt/config.yaml
results in:
I think because I am running HAOS things may be a bit different - do you think I should try the command in the last post in this thread? https://community.home-assistant.io/t/rpi4-bluetooth-on-2022-8-1/447202/6 I am using a RPI 4 with no external BT module (although I hope it will eventually be able to use BT from ESP32's?). But really I am clutching at straws......
We are getting closer!
Bluetooth is complaining about "No discovery started" so let's try start it manually.
Open two ssh sessions. In the first one, type:
bluetoothctl scan on
This should print all MAC addresses nearby.
Keep the first ssh session open, and then retry in the second one:
bluetoothctl connect [01:02:03:04:05:08 <- MAC of fingerbot]
On success it should print
Attempting to connect to 01:02:03:04:05:08
[CHG] Device 01:02:03:04:05:08 Connected: yes
Connection successful
bluetoothctl scan on
Then in a second ssh session: (same result as previous)
In the first ssh terminal, if I just type bluetoothctl
it says AdvertisementMonitor Path Registered
and I get a long rolling list of MAC addresses (including the fingerbot) with RSSI values, etc..... If I then type scan on
it says Discovery Started
and the list contines in much the same way....
If I then type connect [01:02:03:04:05:08 <- MAC of fingerbot]
it connects Connection Successful
It looks like I need to use bluetoothctl
as a separate command from connect
or scan on
etc.....
(and it looks like my two ssh terminals are into different containers? Because bluetoothctl
in one did not allow scan on
in the other..... but I am very much guessing here!)
Hi.... do you think there is anything else I can try here? Thank you.......
BTW, I found this and it is working :-) https://github.com/PlusPlus-ua/ha_tuya_ble
Thanks for getting me looking at this :-)
While I still don't know why my program doesn't work with your setup (sad), I'm glad you find another solution! :)
Happy to keep trying your solution if you have any other ideas?
Hi. This is a great addition to HA - the Adaprox fingerbots are really cheap :-)
I am using HAOS. I have not run any Python in HA - should this run under something like AppDaemon?
And can the script to get the device id, etc - can that be run under HA? Or do you need a separate Python environment to run it under (like a Linux box / VM / etc)?