Closed jochim-vd closed 2 years ago
The error seems to indicate the AccesToken is wrong. Are you able to control the blinds and open/close them (you schould not be if the token is wrong)?
Are you 100% sure that the AccesToken that you use is correct? Was it working before or is this the first time you started using this code?
Regarding the polling, HomeAssistant also supports push updates when a blind stops moving. so if you initialize a move of a blind with a remote or through manual control or something, the blind starts moving and as soon as it reaches its final position and stops it will send a push message and the HomeAssistant state will be updated emidiatly. However this does require multicast messages to work correctly. See https://www.home-assistant.io/integrations/motion_blinds/#troubleshooting for debuging.
I'm having issues too with the multicast part. I have a Unifi network and followed the steps in the guide, yet push via multicast doesn't seem to be working.
I get the same access token error and I can control the blinds via HA when I disable the wait for push. Downside is that it defaults to its standard polling of 10 minutes.
@fabiancamps do you have Brel Blinds or Motion blinds? Where did you get the API key from, a official app?
Is the “Enable multicast enhancement (IGMPv3)” setting disabled for all Unifi acces points (it needs to be set on each acces point seperately from which I understood).
Is the gateway and the homeassistant device connected to the same network on the same VLAN/subnet?
What type of blinds do you have?
I have the Motion Blinds, CM-02 with the mini WiFi bridge. I got the API key from the Motion Blinds app on iOS. Disabled IGMPv3 (also tried disabling IGMP Snooping on the LAN network) but this doesn't work. Other documentation on the internet says that when you want to use multicast on Unifi, it actually should be Enabled instead of Disabled. Gateway/Bridge and HA are on the same VLAN (I'm not using specific IoT VLANs). As mentioned before, I can reach and talk to the blinds via HA, just not over multicast.
@fabiancamps I actually do not have Unifi equipment and are not familiar with it, my guess is that the multicast is some setting in the router/firewall or something.
I think that IGMP Snooping indeed needs to be disabled. Maybe try with the IGMPv3 settings enabled then? I don't know, you can play around with the settings.
@fabiancamps
A easy way to debug the multicast is to run wireshark on a PC on the same VLAN as the gateway and Homeassistant.
Use this filter: ip.src==238.0.0.18 or ip.dst==238.0.0.18
You schould then see the multicast messages of the gateway on your network.
If you move a blind, at the stop of movement you schould see A UDP message in wireshark wich contains all kinds of information about the postion of the blind.
If you do not see any messages then it is probably a problem in your Router, if you do see the messages it is probably a problem on the HomeAssistant device and I can help you further
@fabiancamps do you see exactly this same error message?
Received actionResult: 'AccessToken error', when sending message: '{'msgType': 'WriteDevice', 'mac': '94b97e0d20180003', 'deviceType': '10000000', 'AccessToken': 'xxxxxxxx-xxxx-xx', 'msgID': '20220110211938034', 'data': {'operation': 5}}'
If so I am going to discuss with the manufacturer why this could be happening, because that is very weird, espacially if you are able to control the position of the blinds.
@starkillerOG Yep the access token is correct because I can control the blinds just fine. It's been working for a long time in polling mode.
I also have Unifi AP's (no Unifi switches and router though) and my multicast also isn't working. However, the report messages can be picked up by Node-RED using a UDP node just not by the Motion Blinds integration.
Example report message:
{"msgType":"Report","mac":"94b97e0d20180003","deviceType":"10000000","msgID":"20220111231632183","data":{"type":1,"operation":2,"currentPosition":100,"currentAngle":180,"currentState":3,"voltageMode":1,"batteryLevel":803,"wirelessMode":1,"RSSI":-75}}
I think I tried everything. With IGMP Snooping, without. With IGMPv3, without. With wireshark I don't get to see any multicast traffic whatsoever from ip.src==238.0.0.18 or ip.dst==238.0.0.18. Other multicast devices (Google Cast, AirPlay) all just work fine.
I tried on a different PC and it seems to be working on the broadcasting part: 192.168.1.13 is de WiFi bridge 192.168.1.41 is my phone from where I do the request to adjust the blinds
HA doesn't seem to see this and it's also connected via Ethernet just like my other PC where I did get Wireshark working.
I got it! I reinstalled the integration in HA and chose for Network Interface for "any" instead of my HA instance IP.
@fabiancamps good to hear it is finally working :) Those multicast messages are a nightmare, on so many diffrent systems and routers this goes wrong, but mostely it is some setting in a device and not so much the actuall code that has a problem.
@fabiancamps do you still have the 'AccessToken error'
after the multicast is now working?
@jochim-vd please follow the same steps as @fabiancamps to see if you can get multicast messages on a PC in wireshark, and try a few diffrent Network Interfaces (during setup of the HomeAssistant integration).
@fabiancamps could you post your final settings for the Unify AP's that are working? IGMP Snooping on/off IGMPv3 on/off
@starkillerOG I am able to capture multicast messages using Wireshark. They even show up in Home Assistant itself using the UDP node in Node-RED, but they are not picked up by the Motion Blinds integration.
I reinstalled the integration, trying multiple interfaces, but without luck. My HA machine has 2 NIC's (one on my regular network and one on my IoT network), I tried them both and the "any" option but none worked.
@jochim-vd it probably has to do with these lines of code that create the multicast UDP socket: https://github.com/starkillerOG/motion-blinds/blob/c9729794885699557397f357a452f958d9019ba6/motionblinds/motion_blinds.py#L124-L153
I am defenitly not an export in these low level socket functions.
You could try the following python script on a PC and on your HomeAssistant device: Filling in the correct IP, key and play around with the interface, you could try "0.0.0.0" which is not availalbe (yet) as an option in HomeAssistant.
import asyncio
from motionblinds import AsyncMotionMulticast, MotionGateway
gateway_ip = "192.168.1.IP"
gateway_key = "xxxxxxxx-xxxx-xx"
UDP_interface = "0.0.0.0"
async def asyncio_demo(loop):
def callback_func_gateway():
print(m)
def callback_func_blind():
for blind in m.device_list.values():
print(blind)
motion_multicast = AsyncMotionMulticast(interface = UDP_interface)
m = MotionGateway(ip=gateway_ip, key=gateway_key, multicast = motion_multicast)
await loop.run_in_executor(None, m.GetDeviceList)
await loop.run_in_executor(None, m.Update)
await motion_multicast.Start_listen()
m.Register_callback("1", callback_func_gateway)
for blind in m.device_list.values():
blind.Register_callback("1", callback_func_blind)
blind_0 = list(m.device_list.values())[0]
loop.run_in_executor(None, blind_0.Update)
await asyncio.sleep(30)
motion_multicast.Stop_listen()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio_demo(loop))
You could also try changing the code in _create_mcast_socket linked above and see if you can get it to work. Depending on your expertise with python sockets.
For me it is really hard to help you since it works on my end on my network and devices. This probably has to do with your network setup/specific device.
Adding this for it might help someone in the future:
I had the same problem with multicast updates. My homeassistant runs in docker with network=host option set. Installed tcpdump in the homeassistant docker to make sure the multicast packets arrived (they did) but got the "[motionblinds.motion_blinds] Timeout of 5.0 sec occurred ...." etc.
Next I changed the interface entry in the motion_blinds config from my host IP to "any" and the updates worked!
Bonus: Since I have 6 blinds and was to lazy to reinstall/reconfigure the integration I changed the interface directly in the homeassistant config file: .storage/core.config_entries, this is the entry (key removed): { "entry_id": "8d3bf3c93084c45fee35d4fb9c77b274", "version": 1, "domain": "motion_blinds", "title": "Motion Blinds Gateway", "data": { "host": "192.168.2.13", "api_key": "xxxxxxxx-xxxx-xx", "interface": "any" }, "options": { "wait_for_push": true }, "pref_disable_new_entities": true, "pref_disable_polling": false, "source": "user", "unique_id": "e868e7c229f0", "disabled_by": null },
Restart after change. WARNING: do this at your own risk.
This PR https://github.com/home-assistant/core/pull/68852 will actually eliminate the need to specify the interface. All possible interfaces will just by tried and tested during setup and at each boot of HomeAssistant. Automatically a working interface will be searched (including the "any" option).
Even if the network changes, a simple restart of the integration/homeassistant will update the interface.
Therefore I will close this issue since it has been resolved.
If you have any other problems or questions, feel free to open a new issue!
The hub is working and connected to HA, but the entities only update state by HA polling the hub. I think it may be related to these 2 errors I'm getting:
and
Do you have more info on this error?