eschava / broadlink-mqtt

MQTT client to control BroadLink devices
MIT License
217 stars 60 forks source link

Install instructions no longer work #87

Open digginsa opened 3 years ago

digginsa commented 3 years ago

Hello,

I have some BG1 and have followed the install instructions but always get the below error when running ./mqtt.py

File "./mqtt.py", line 4, in import broadlink # pip install broadlink File "/home/digginsa/.local/lib/python2.7/site-packages/broadlink/init.py", line 100 dev_type: int, ^ SyntaxError: invalid syntax

eschava commented 3 years ago

Looks like new release of python-broadlink library doesn't work with Python 2.7, only Python 3

digginsa commented 3 years ago

Looks like new release of python-broadlink library doesn't work with Python 2.7, only Python 3

Thanks for the response, I updated my Python to 3.7 but still get the same error any tips? appreciate in advance.

eschava commented 3 years ago

What command do you use to run mqtt.py with Python 3.7?

digginsa commented 3 years ago

im just running ./mqtt.py currently

What command do you use to run mqtt.py with Python 3.7?

im just running ./mqtt.py currently

eschava commented 3 years ago

I guess it still uses Python 2.7 Could you please try command python3 mqtt.py instead?

digginsa commented 3 years ago

I guess it still uses Python 2.7 Could you please try command python3 mqtt.py instead?

now het the following I did the pip install -r requirements.txt and paho installed but the same error.

Traceback (most recent call last): File "mqtt.py", line 3, in import paho.mqtt.client as paho # pip install paho-mqtt ModuleNotFoundError: No module named 'paho'

eschava commented 3 years ago

pip also should be from Python 3 e.g. pip3 or python3 -m pip install -r requirements.txt

digginsa commented 3 years ago

pip also should be from Python 3 e.g. pip3 or python3 -m pip install -r requirements.txt

progress (I think) appreciate, just need to sort out the custom.conf now.

Traceback (most recent call last): File "mqtt.py", line 587, in devices = get_device(cf) File "mqtt.py", line 347, in get_device return configure_device(devices[0], topic_prefix) File "mqtt.py", line 395, in configure_device device.auth() File "/home/digginsa/.local/lib/python3.7/site-packages/broadlink/device.py", line 198, in auth check_error(response[0x22:0x24]) File "/home/digginsa/.local/lib/python3.7/site-packages/broadlink/exceptions.py", line 137, in check_error raise exception(error_code) broadlink.exceptions.AuthenticationError: [Errno -1] Authentication failed

eschava commented 3 years ago

"Authentication failed" means that the Broadlink device is currently connected to the phone application. In order to use it by this tool you need to reset the device and connect it to broadlink-mqtt only I'll add this to the main instructions

digginsa commented 3 years ago

I’m using a BG1 do I need to remove it from the app?

From: Eugene Schava [mailto:notifications@github.com] Sent: 10 November 2020 14:12 To: eschava/broadlink-mqtt broadlink-mqtt@noreply.github.com Cc: digginsa adam.diggins@me.com; Author author@noreply.github.com Subject: Re: [eschava/broadlink-mqtt] Install instructions no longer work (#87)

"Authentication failed" means that the Broadlink device is currently connected to the phone application. In order to use it by this tool you need to reset the device and connect it to broadlink-mqtt only I'll add this to the main instructions

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eschava/broadlink-mqtt/issues/87#issuecomment-724726927 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFX2TEROMAWEETFKN5EPTDSPFC4XANCNFSM4TQP56VQ . https://github.com/notifications/beacon/AOFX2TGEUIVQJ7WDWQ2BGKDSPFC4XA5CNFSM4TQP56V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFMZHJDY.gif

eschava commented 3 years ago

I'm not sure. You have either remove it from the mobile app or reset device settings to wipe out the connection between device and application

digginsa commented 3 years ago

Ok so making progress and thank you for the help, it needs to be in the app still, its connecting but I am getting the following any ideas?

[2020-11-10 16:40:01,304] DEBUG Connected to 'BG1' Broadlink device at '192.168.1.73' (MAC 54:48:e6:a7:df:24) and started listening for commands at MQTT topic having prefix 'broadlink/'

[2020-11-10 16:40:02,211] DEBUG Connected to MQTT broker, subscribing to topic broadlink/#

[2020-11-10 16:40:02,211] WARNING OOOOPS! MQTT disconnection

[2020-11-10 16:40:13,224] DEBUG Connected to MQTT broker, subscribing to topic broadlink/#

[2020-11-10 16:40:13,225] WARNING OOOOPS! MQTT disconnection

From: Eugene Schava [mailto:notifications@github.com] Sent: 10 November 2020 16:42 To: eschava/broadlink-mqtt broadlink-mqtt@noreply.github.com Cc: digginsa adam.diggins@me.com; Author author@noreply.github.com Subject: Re: [eschava/broadlink-mqtt] Install instructions no longer work (#87)

I'm not sure. You have either remove it from the mobile app or reset device settings to wipe out the connection between device and application

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eschava/broadlink-mqtt/issues/87#issuecomment-724822294 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFX2TDNBKNYR7WHXVD35L3SPFULZANCNFSM4TQP56VQ . https://github.com/notifications/beacon/AOFX2TBWLL7DYEPISFPE5TTSPFULZA5CNFSM4TQP56V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFMZ6SFQ.gif

digginsa commented 3 years ago

Ignore my last message, it was a capital in the password that was throwing the error

From: Eugene Schava [mailto:notifications@github.com] Sent: 10 November 2020 16:42 To: eschava/broadlink-mqtt broadlink-mqtt@noreply.github.com Cc: digginsa adam.diggins@me.com; Author author@noreply.github.com Subject: Re: [eschava/broadlink-mqtt] Install instructions no longer work (#87)

I'm not sure. You have either remove it from the mobile app or reset device settings to wipe out the connection between device and application

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eschava/broadlink-mqtt/issues/87#issuecomment-724822294 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFX2TDNBKNYR7WHXVD35L3SPFULZANCNFSM4TQP56VQ . https://github.com/notifications/beacon/AOFX2TBWLL7DYEPISFPE5TTSPFULZA5CNFSM4TQP56V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFMZ6SFQ.gif

digginsa commented 3 years ago

Once again thank you for the support, I now have the socket working just need to work out now how to add additional sockets, as an update this is what I had to do to get it working:

1/ I had to remove the socket from the app as it was not broadcasting MQTT messages even though it was connected to boradlink-mqtt successfully, this is due to the app having it cloud connected

2/ put the BG1 socket into AP mode

3/ Build a linux laptop and install bpython3 broadlink

4/ join the laptop to the BG1 AP network

5/ run broadlink_cli –joinwifi SSID SSIDPASSWORD

6/ success

From: Eugene Schava [mailto:notifications@github.com] Sent: 10 November 2020 16:42 To: eschava/broadlink-mqtt broadlink-mqtt@noreply.github.com Cc: digginsa adam.diggins@me.com; Author author@noreply.github.com Subject: Re: [eschava/broadlink-mqtt] Install instructions no longer work (#87)

I'm not sure. You have either remove it from the mobile app or reset device settings to wipe out the connection between device and application

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eschava/broadlink-mqtt/issues/87#issuecomment-724822294 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFX2TDNBKNYR7WHXVD35L3SPFULZANCNFSM4TQP56VQ . https://github.com/notifications/beacon/AOFX2TBWLL7DYEPISFPE5TTSPFULZA5CNFSM4TQP56V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFMZ6SFQ.gif

eschava commented 3 years ago

just need to work out now how to add additional sockets

what mode (device_type) do you use in your configuration?

digginsa commented 3 years ago

For the first device I did direct connection, I am going to try lookup so I have made these changes to the config.conf do they look right? (Second switch I still need to configure to get the real MAC)

Type of device. Valid options are 'lookup', 'multiple_lookup', 'rm', 'rm4', 'sp1', 'sp2', 'a1', 'mp1', 'dooya', 'bg1'

device_type = 'lookup' # use lookup

lookup parameters

lookup_timeout = 20

local_address = '127.0.0.1'

parameters for direct connection

device_host = '192.168.1.73'

device_mac = '24:df:a7:e6:48:54'

MQTT connection parameters

mqtt_broker = 'localhost' # default: 'localhost'

mqtt_port = 1883 # default: 1883

mqtt_clientid = 'broadlink'

mqtt_username = 'root'

mqtt_password = 'Welcome1'

mqtt_topic_prefix = 'broadlink/'

mqtt_multiple_subprefix_format = 'BG1_192.168.1.73_24:df:a7:e6:48:54/BG1_192.168.1.74_25:df:a7:e6:48:54/' # use only with 'multiple_lookup' device type (allowed parameters are {type}, {host}, {mac}, {mac_nic})

mqtt_birth_topic = 'clients/broadlink'

mqtt_birth_payload = 'Hello!'

mqtt_will_topic = 'clients/broadlink'

mqtt_will_payload = 'Adios!'

From: Eugene Schava [mailto:notifications@github.com] Sent: 11 November 2020 10:30 To: eschava/broadlink-mqtt broadlink-mqtt@noreply.github.com Cc: digginsa adam.diggins@me.com; Author author@noreply.github.com Subject: Re: [eschava/broadlink-mqtt] Install instructions no longer work (#87)

just need to work out now how to add additional sockets what mode (device_type) do you use in your configuration?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eschava/broadlink-mqtt/issues/87#issuecomment-725342108 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFX2TF6Y73JIKUOU5NK2DLSPJRTRANCNFSM4TQP56VQ . https://github.com/notifications/beacon/AOFX2TGAJCUBS44HSNYXRW3SPJRTRA5CNFSM4TQP56V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFM55PHA.gif

eschava commented 3 years ago

You should use multiple_lookup type to use autodiscovery for multiple devices

digginsa commented 3 years ago

Think I mis-understood the instructions, so if I changed my config to juts look like the below, I would not need to put ip and mac of the devices in?

device_type = 'multiple_lookup' mqtt_multiple_subprefixformat = '{type}{mac_nic}/

From: Eugene Schava [mailto:notifications@github.com] Sent: 11 November 2020 10:36 To: eschava/broadlink-mqtt broadlink-mqtt@noreply.github.com Cc: digginsa adam.diggins@me.com; Author author@noreply.github.com Subject: Re: [eschava/broadlink-mqtt] Install instructions no longer work (#87)

You should use multiple_lookup type to use autodiscovery for multiple devices

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eschava/broadlink-mqtt/issues/87#issuecomment-725345347 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFX2TGBBH6SCCWTGEU6PBTSPJSKNANCNFSM4TQP56VQ . https://github.com/notifications/beacon/AOFX2TGEO6YKZEUSE5DKBJDSPJSKNA5CNFSM4TQP56V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFM56IQY.gif

eschava commented 3 years ago

Yes, this is what auto-lookup is for The only thing that is essential for lookup modes is correct local_address if your device is connected to multiple networks

digginsa commented 3 years ago

Perfect that’s working it’s now seeing two sockets, last challenge I am seeing this:

[2020-11-11 12:03:52,154] ERROR MQTT topic broadlink/power/2 has no recognized device reference, expected one of BG1_192.168.1.71/,BG1_192.168.1.26/

[2020-11-11 12:03:52,155] ERROR MQTT topic broadlink/power/1 has no recognized device reference, expected one of BG1_192.168.1.71/,BG1_192.168.1.26/

From: Eugene Schava [mailto:notifications@github.com] Sent: 11 November 2020 11:34 To: eschava/broadlink-mqtt broadlink-mqtt@noreply.github.com Cc: digginsa adam.diggins@me.com; Author author@noreply.github.com Subject: Re: [eschava/broadlink-mqtt] Install instructions no longer work (#87)

Yes, this is what auto-lookup is for The only thing that is essential for lookup modes is correct local_address if your device is connected to multiple networks

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eschava/broadlink-mqtt/issues/87#issuecomment-725372479 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFX2TA3JVRVB6PWDZJREL3SPJZB3ANCNFSM4TQP56VQ . https://github.com/notifications/beacon/AOFX2TGY6ELOD4QORO3BBZ3SPJZB3A5CNFSM4TQP56V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFM6E4PY.gif

eschava commented 3 years ago

Looks like you changed mqtt_multiple_subprefixformat to {type}{host} So now you need to send commands to the topic like broadlink/BG1_192.168.1.71/power/1 not broadlink/power/1

digginsa commented 3 years ago

Yes I had to change to {type]_[host} as when I used [mac_nic} it only used the first few characters of the mac address which ended up being the same so had duplicates and threw errors.

All working now successfully controlling both switches via home assistant, last step getting mqtt.py to run all the time

Thanks so much for your help this has been a very interesting project

From: Eugene Schava [mailto:notifications@github.com] Sent: 11 November 2020 12:18 To: eschava/broadlink-mqtt broadlink-mqtt@noreply.github.com Cc: digginsa adam.diggins@me.com; Author author@noreply.github.com Subject: Re: [eschava/broadlink-mqtt] Install instructions no longer work (#87)

Looks like you changed mqtt_multiple_subprefixformat to {type}{host} So now you need to send commands to the topic like broadlink/BG1_192.168.1.71/power/1 not broadlink/power/1

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eschava/broadlink-mqtt/issues/87#issuecomment-725391441 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AOFX2TDRFV3YX22AIFQEN7LSPJ6HNANCNFSM4TQP56VQ . https://github.com/notifications/beacon/AOFX2THNZ5E33QHFMWZSDULSPJ6HNA5CNFSM4TQP56V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFM6JQUI.gif

dal31b05 commented 7 months ago

pip also should be from Python 3 e.g. pip3 or python3 -m pip install -r requirements.txt

I have tried this but I still get the ModuleNotFoundError: No module named 'paho' error.

paho is definitely installed as I get Requirement already satisfied if I run the installer again. I have tried adding the package path to sys.path but that didn't help. Not sure what I can try next.