Sonoff DW2 wifi - Home Assistant Switch to Binary, and get last state when unavaliable

Hola, where did you write this code, to convert the battery level to %?
I’m using HACS integration: Battery State Card / Entity Row
As you can see in the following picture, just the first one fails. The one with a Sonoff DW2 entity.
bateria

What do you mean?

Battery percentage is a “new sensor” you have to add.
That code will go at configuration.yaml or in sensors.yaml if you have that file “included” in the configuration.yaml
So you can choose to use any of them.
Just note I don’t know the Min voltage to be 0% so I just took 2v as 0% and 3v as 100%


Probably will need to adjust to 2.2 or little more. Let’s see when stops working in a few months.

Here you can see, after a reboot, all sensors related to DW2 become unavailable except the one coming from the sql, saved as last state.

I can’t for the life of me register the DW2 RF as closed with the Ewelink app.

Add - Alarm and open the door. This is fine.

But when I click ADD when open then shut the door it doesn’t register…

Any ideas?

Thanks

Hello Good afternoon, I would like to know how I can integrate the DW2 wifi device in home assistant, thank you, I am trying but there is no way.

You will need to install GitHub - hacs/integration: HACS , follow the instructions. and then it finds the sensor automatically

Regards

I have the hacs installed but I already have an ewelink switch in homeasistant, these if it detects them but the DW2 wifi does not, I have created a sensors.yaml and I have written the FelisucoVFR code
Felix, what’s up, but there is no way, I understand that in cloud mode, two devices at the same time does not work? Thanks

It seems to me that this device the DW2 wifi fails more than a fairground shotgun, in the app it works perfectly but in the home assistant it is worth it, at least to me, it will be a matter of looking for another brand that does not have problems, thanks to all for the answers, a hug.

Sorry about the very very late respond. Sure this is useless now…
Two sensors work perfect but each of them need it’s own code with different names. That’s all.
I still have it working and I have to say it is reliable. Since last AlexxIT versions as integration it is even easier as you already have the voltage as a separate sensor, so no need that template.
After near two years working I have to say their batteries last near a year.
My only complain is about the size. Rest is good for me.

Excuse me to come back with this thread, but after the last upgrades, the % for the battery level doesn’t work anymore, and I’m going nuts.
What I’m trying now is as follow, but doesn’t work, any ideas, please:

# Bateria del sensor PuertaEntrada
template:
  - sensor:
    - name: "PuertaEntrada_battery_perc"
      unit_of_measurement: "%"
      value_template: "{{ ((states('sensor.sonoff_1000e0e148_battery_voltage')-2)|float/0.01)|round(1) }}"

:sweat_smile: :sweat_smile: I solved this way:

  - platform: template
    sensors:
      puertaentrada_battery_perc:
        friendly_name: "PuertaEntrada_battery_perc"
        unit_of_measurement: "%"
        value_template: "{{ ((states('sensor.sonoff_1000e0e148_battery_voltage')|float-2)/(0.01)|float)|round(0) }}"
1 Like

you got the voltage, and then voltage -2 … and then / 0.01

but there´s no relation between voltage and battery level…

for example, my voltage is 2,581 … using your math, my battery level is 58%… no it´s not… i just replaced the batteries…they are 100%

how did you solve it?
I know my solution wasn’t exact but an aprox. at least

I didn’t… still no solution… DW2 used to have a battery-level entity…but not anymore… I don’t know why it was deprecated

but your math is wrong…like I said…there´s no relationship between voltage and battery level.

maybe with tasmota…

Just in case someone is still interested:

    door_garaje_pct_battery:
      friendly_name: Batería puerta garaje PCT
      unit_of_measurement: "%"
      value_template: >-
        {% set minvdc = 2.25 %} # Minumum voltage 0%
        {% set maxvdc = 2.80 %} # Max voltage 100%
        {% if states('sensor.puerta_garage_battery_voltage')|float < minvdc %}
          0.0
        {% elif states('sensor.puerta_garage_battery_voltage')|float > maxvdc %}
          100.0
        {% else %}
          {{ ( 100/(maxvdc-minvdc) * ((states('sensor.puerta_garage_battery_voltage')|float - minvdc)))|round(0) }}
        {% endif %}
      device_class: battery

@Guilherme_Gimenes It can be linear, logaritmic or whatever, but there is always a relation.