HASS-sonoff-ewelink icon indicating copy to clipboard operation
HASS-sonoff-ewelink copied to clipboard

sonoff Dw2 support?!

Open DavidFFerreira opened this issue 3 years ago • 13 comments

sonoff Dw2 support?! Can you please add support for this?

DavidFFerreira avatar Aug 05 '20 20:08 DavidFFerreira

Looking for this too. Purchased the DW2 instead of the zigbee equivalent SNZB-04, and I don't want to mess with firmware flashing. May just start a return unless supporting these is trivial.

Home assistant will detect the state quickly whenever it changes, but then a few seconds later it changes to unavailable. Can anyone explain?

alexwohlbruck avatar Aug 31 '20 22:08 alexwohlbruck

@alexwohlbruck I found a way to have the Dw2 working fine in my HA Usigng Log as data support

sensor: - platform: sql db_url: !secret db_url
queries: - name: Sonoff_GetLastState query: > SELECT state FROM "states" WHERE entity_id = 'switch.sonoff_1000e0ed27' AND state NOT IN ( 'unavailable', 'unknown') ORDER BY Last_Updated desc
LIMIT 1; column: 'state'

sonoff: username: !@Secret Username password: !@Secret Password scan_interval: 60 #(optional, lower values than 60 won't work anymore!) grace_period: 600 #(optional) api_region: 'eu' #(optional) entity_prefix: True #(optional) debug: False #(optional)

binary_sensor:

  • platform: template sensors: front_door: device_class: opening value_template: > {{ ((is_state('sensor.Sonoff_GetLastState', 'off')) and is_state('switch.sonoff_1000e0ed27', 'on')) or ((is_state('sensor.Sonoff_GetLastState', 'on')) and is_state('switch.sonoff_1000e0ed27', 'unavaliable')) }}

After that you can use your Binary sensor for

DavidFFerreira avatar Sep 01 '20 09:09 DavidFFerreira

@alexwohlbruck I found a way to have the Dw2 working fine in my HA Usigng Log as data support

sensor:

  • platform: sql db_url: !secret db_url queries:
  • name: Sonoff_GetLastState query: > SELECT state FROM "states" WHERE entity_id = 'switch.sonoff_1000e0ed27' AND state NOT IN ( 'unavailable', 'unknown') ORDER BY Last_Updated desc LIMIT 1; column: 'state'

sonoff: username: !@secret Username password: !@secret Password scan_interval: 60 #(optional, lower values than 60 won't work anymore!) grace_period: 600 #(optional) api_region: 'eu' #(optional) entity_prefix: True #(optional) debug: False #(optional)

binary_sensor:

  • platform: template sensors: front_door: device_class: opening value_template: > {{ ((is_state('sensor.Sonoff_GetLastState', 'off')) and is_state('switch.sonoff_1000e0ed27', 'on')) or ((is_state('sensor.Sonoff_GetLastState', 'on')) and is_state('switch.sonoff_1000e0ed27', 'unavaliable')) }}

After that you can use your Binary sensor for

FairozJaf avatar Jan 09 '21 14:01 FairozJaf

@DavidFFerreira Thank you for the code. Please note that I'm new to HA and YAML. The code won't work. I think the alignment spaces are out. Can you please assist by repost or post a text file for download.

FairozJaf avatar Jan 11 '21 07:01 FairozJaf

Hi There, dont bother with this code, right now you can do a total integration with sonoff adon in HA. With works great and there is no need for that code anymore

DavidFFerreira avatar Jan 11 '21 12:01 DavidFFerreira

@DavidFFerreira Thank you. My 6 other sonoff devices works using HACS in HA. The DW2 does not. It does not come up in Entities. I guess I'll have to do some more trouble shooting. Regards

FairozJaf avatar Jan 11 '21 12:01 FairozJaf

Is anyone have a the same problem as me with the Sonoff DW2 not showing in Entities in HA? Also let me know if it works for you and how you got it to work. I now have 8 x Sonoff devices working with problems. It's just the DW 2 that's not working.

FairozJaf avatar Jan 16 '21 20:01 FairozJaf

DW2 only supports “easy” SSID passwords. Only regular characters and numbers.

FelisucoVFR avatar Jan 31 '21 15:01 FelisucoVFR

@FelisucoVFR Thank you. I checked. I don't have special characters for SSID. I can see the DW2 on the network and also ping it. It just does not appear in HA. All other sonoff devices appear fine. I might look at flashing it with Tasmota or something when i get time. regards

FairozJaf avatar Feb 09 '21 05:02 FairozJaf

Ahh, ok. So it is paired already. Give me some time and I will tell you how I did and how I made it holding the state even after a HA reboot. If I remember correct I did the search in the Development tools by the third column using “dw2”. Not at entity name, at the last column.

Regards

El 9 feb 2021, a las 6:29, FairozJaf [email protected] escribió:  @FelisucoVFR Thank you. I checked. I don't have special characters for SSID. I can see the DW2 on the network and also ping it. It just does not appear in HA. All other sonoff devices appear fine. I might look at flashing it with Tasmota or something when i get time. regards

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

FelisucoVFR avatar Feb 09 '21 07:02 FelisucoVFR

@FairozJaf

image

Here it is how I could find it. Not hard but at the begining I was just doing the search at entity column. Once you have this solved, you will want to make it keep the last known status as it use to loose it after a HA restart and sometimes itself, indicating unavailable instead, so let us know when you can find it to go to the next step.

FelisucoVFR avatar Feb 09 '21 20:02 FelisucoVFR

at Configuration.yaml:

`# Garaje DW2 WIFI Door sensor data

  • platform: template sensors: door_open_garaje: friendly_name: Puerta Garaje raw-don't use this value_template: "{{ states('binary_sensor.sonoff_10010xxxxx') }}"

Hay una parte para mantener estado del DW2 Wifi según el último guardado en el sql

Ver binary sensors door_open_garaje_laststate

  bateria_puerta_garaje:
    friendly_name: Batería puerta garaje volts
    unit_of_measurement: V
    value_template: "{{ state_attr('binary_sensor.sonoff_10010xxxxx', 'battery') }}"

Set percentage to 0% at 2v (the -2 before the "float")

  bateria_puerta_garaje_pct:
    friendly_name: Batería puerta garaje PCT
    unit_of_measurement: '%'
    value_template: "{{ ((state_attr('binary_sensor.sonoff_10010xxxxx', 'battery')-2)|float/0.01)|round(0) }}"
    device_class: battery
  rssi_garaje:
    friendly_name: Señal Wifi
    unit_of_measurement: dbi
    value_template: "{{ state_attr('binary_sensor.sonoff_1001039bba', 'rssi') }}"
    device_class: signal_strength

To keep the last useful state from DW2 Wifi

  • platform: sql queries:
    • name: sonoff_dw2_get_last_state query: SELECT state FROM states WHERE entity_id like '%binary_sensor.sonoff_10010xxxxx%' AND state NOT IN ('unavailable', 'unknown') ORDER BY Last_Updated desc LIMIT 1; column: state`

And the binary_sensor to get the state according last state recorded instead of the actual. Very usefull to know the state after a restart until it receives the actual which may take a long while:

binary_sensor:

  • platform: template sensors: door_open_garaje_laststate: friendly_name: Garaje door value_template: >- {% if states('binary_sensor.sonoff_10010xxxxx') == 'on' %} {{'on'}} {% elif states('binary_sensor.sonoff_10010xxxxx') == 'off' %} {{'off'}} {% else %} {% if states('sensor.sonoff_dw2_get_last_state') == 'on' %} {{'on'}} {% elif states('sensor.sonoff_dw2_get_last_state') == 'off' %} {{'off'}} {% else %} {{ states('sensor.sonoff_dw2_get_last_state') }} {% endif %} {% endif %} device_class: door

Hope it works for you too. Just need to replace the "xxxxx" with your sensor data. I have found this solution around a few forums. It took me a while adapting it but after restarting HA it worked nice.

FelisucoVFR avatar Feb 09 '21 20:02 FelisucoVFR

Thank you @FelisucoVFR The DW2 does not appear in HA. I search everything. It works in the eWelink App.
I search as you suggested and also device ID. Used the browser text search for the whole page. I also deleted ".sonoff.json". New one created. I find the deviceid & name in the ".sonoff.json" file. but not anywhere in HA. I've got 10 other Sonoff Devices that work great. I'm really out of ideas.

FairozJaf avatar Feb 13 '21 07:02 FairozJaf