beveradb / sonoff-lan-mode-homeassistant

Home Assistant platform to control Sonoff switches running the latest Itead firmware, locally (LAN mode).
MIT License
74 stars 36 forks source link

Unexpected error in setup_connection(): could not convert string to float: '8.0.1' #72

Closed tomascrespo closed 5 years ago

tomascrespo commented 5 years ago

Hi! I've just installed this component. It will be wonderfull for my setup.

I get the module loaded and the entity created, but I can use it. I have a lot of this errors on log: 2019-07-29 23:56:13 ERROR (MainThread) [homeassistant.components.switch.sonoff_lan_mode] Unexpected error in setup_connection(): could not convert string to float: '8.0.1'

Any idea?

My Home Assistant is 0.96.5 on Raspbian Buster

PD: In README of this project should say that you have to download manifest.json file too, not only switch.py

mattsaxon commented 5 years ago

This is due to using WebSockets 8.0.1, the string '8.0.1' cannot be converted to a float.

@tomascrespo, how did websockets 8.0.1 get installed, HA uses WS 6.0

tomascrespo commented 5 years ago

I have no idea. Could it be related with Python version?

I upgraden (manually) to Python 3.7, but I don't have any other custom installation.

Any solution?

mattsaxon commented 5 years ago

If you are happy to do such manual installations, an easy fix would be to do a specific install of WS 8.0. If that causes other issues it should be easy to regress

mattsaxon commented 5 years ago

I'd recommend trying "pip install websockets==8.0". However note that this component to my knowledge has only been tested with 6.0 and 7.0

tomascrespo commented 5 years ago

I've just done: pip install 'websockets==6.0.0' --force-reinstall And now I have websockets 6.0.0. Now I'm having the message in the log.

However I can't get my sonoff POW R2 (firmware 3.3.0) working. In Developer tools -> States I get 'unavailable' as state for the sonoff. I've created a entity-button card action and it does nothing.

My configuration.yaml:

switch:
  - platform: sonoff_lan_mode
    name: Depuradora
    host: 192.168.2.190
    icon: mdi:pool

My card:

entity: switch.depuradora
hold_action:
  action: more-info
show_icon: true
show_name: true
tap_action:
  action: toggle
type: entity-button

The sonoff is on LAN mode, becaus I can only accessit on WiFi, not on mobile data

mattsaxon commented 5 years ago

This component only support firmware 1.8 and 2.x

You need to use my fork for firmware 3.x.

tomascrespo commented 5 years ago

I have run your test script:

pi@ICC-Solar:~ $ python3 test_sonoff.py
2019-07-30 16:23:37 - DEBUG - Sonoff class initialising
2019-07-30 16:23:37 - DEBUG - initializing websocket
2019-07-30 16:23:37 - INFO - WebsocketListener initialising, connecting to host: ws://192.168.2.190:8081/
2019-07-30 16:23:37 - DEBUG - attempting to call WebSocketApp run_forever with ping_interval: 145

and it stops at this point

tomascrespo commented 5 years ago

This component only support firmware 1.8 and 2.x

You need to use my fork for firmware 3.x.

I will give it a try

tomascrespo commented 5 years ago

When you say my component, do you mean mine @mattsaxon or @beveradb. This repo is @beveradb’s not mine.

Your switch is firmware 3.x, so you cannot use the code in this repo. Please use my fork of the repo

I realaised now. All my test until this point were with @beveradb repo.

Now I'm testing @mattsaxon repo. One thing. In your fork, should I block the sonoff of connecting to the internet?

In your README you say:

switch:
  - platform: sonoff_lan_mode_r3
    name: // Switch Name
    device_id: // **Local IP** address of device
    api_key: // [Optional] Custom icon for device

Local IP? or device ID? I think is Device ID, because there is an example above.

tomascrespo commented 5 years ago

This is my configuration.yaml with @mattsaxon repo:

switch:
  - platform: sonoff_lan_mode_r3
    name: Piscina
    device_id: 1000916149
    api_key: 123b1213-2fa6-4ef2-a27c-718fae8ec06d
    icon: mdi:pool

And now I getting this errors:

2019-07-30 16:43:39 ERROR (zeroconf-ServiceBrowser__ewelink._tcp.local.) [homeassistant.components.switch.sonoff_lan_mode_r3] Error decrypting for device 1000916149: Invalid base64-encoded string: number of data characters (249) cannot be 1 more than a multiple of 4, probably wrong API key
2019-07-30 16:44:13 ERROR (zeroconf-ServiceBrowser_eWeLink_1000916149._ewelink._tcp.local.) [homeassistant.components.switch.sonoff_lan_mode_r3] Error decrypting for device 1000916149: Invalid base64-encoded string: number of data characters (249) cannot be 1 more than a multiple of 4, probably wrong API key
2
mattsaxon commented 5 years ago

Local IP? or device ID? I think is Device ID, because there is an example above.

Correct device id, i've corrected the readme, thanks

The errors says the API key is wrong. You look like you have the correct format, are you sure the API key is correct..... the seems to be 2 API keys sometime, an api_key and a self_api key. You must use the api_key, how did you capture it?

tomascrespo commented 5 years ago

I did capture with the instructions in your repo. I got this values: {"deviceid":"1000916149","apikey":"123b1213-2fa6-4ef2-a27c-718fae8ec06d","accept":"post","chipid":"001BA856"}

I find strange that your component don't need the local ip address of the sonoff device

mattsaxon commented 5 years ago

Honestly it doesn't need the IP address, it uses mDNS to discover it.

I've found the issue I think, I haven't tested with a POW R2 before, so the message is longer than for other devices. I need to make a code change, since I don't have one to test with are you happy to be my tester, it may take a few goes!

mattsaxon commented 5 years ago

@tomascrespo I've posted an updated zip file in my repo that I think will fix it. If it doesn't can you post a debug log please?

tomascrespo commented 5 years ago

I will try in a few hours and report...

Great job @mattsaxon !!! 👏 Now is working perfectly! I can switch on and off my sonoff POW R2 from Home Assistant without need of flashing it with an alternative firmware. Even more, I think your code doesn´t need that the sonoff is on LAN Mode, isn´t it?

One more thing. Would it be possible to get data from the sonoff, like current (Amps or Watts)?

mattsaxon commented 5 years ago

Even more, I think your code doesn´t need that the sonoff is on LAN Mode, isn´t it?

With firmware 3.x you don't need to set the device into LAN mode, it works by default.

Amps or Watts

This would certainly be possible, but I don't have a device to test with.

If you could open a specific issue for this feature request and post a debug log from your setup I can see if I can add.