It seems that DW2 as many other devices only works if you use and pay the cloud of home assistant.
I use the alexxIT addon, have 2 DW2 sensors but didn’t work.
Read the documentation of alexxIT.
Problem is, that it also goes away when the sensors go offline, so I went to sqlite to pull the last state also for the battery with this:
* name: Sonofflock_GetbatteryState
query: "SELECT substr(attributes, instr(attributes, 'battery')+10,5) FROM states WHERE entity_id like '%binary_sensor.sonoff_1000e0e51a%' AND state NOT IN ('unavailable') ORDER BY Last_Updated desc LIMIT 1"
column: 'attributes'
Now I’ve tried different string organization and I have tested it in the sqlite add-on and it pulls the voltage value, but when I go to the entity it says state unknown
Hi guys,
Many thanks for your ideas!
I could make the battery % work perfect. I have modify the formula to make the 0% at 2volts as I don’t think is going to work at all at that low voltage. Just added a substract and changed the numbers to: value_template: "{{ ((state_attr('binary_sensor.sonoff_xxx', 'battery')-2)|float/0.01)|round(1) }}"
I could not make the other issue work. getting some errors not able to solve yet.
Mainly I am receiving an error at “column: ‘state’”. I will keep trying and listening you…
I am using them with that alexxIT addon. Only issue is the described here about the status lost and battery in volts, but they work seamless like the rest of sonoff devices.
# To find the last 'healthy' state from the SonOff DW2 Wifi
- platform: sql
# db_url: !secret db_url. Not needed if the standard one is used
queries:
- name: sonoff_dw2_get_last_state
query:
SELECT state
FROM states
WHERE entity_id like '%binary_sensor.sonoff_1001039bba%'
AND state NOT IN ('unavailable', 'unknown')
ORDER BY Last_Updated desc
LIMIT 1;
column: state
Then, calling the “sensor.door_open_garaje_laststate” inside the lovelace entity card, it made the magic.
I must add I have discover just right now, my DW2 Wifi is refreshing its status by itself. It takes >30’ but it refresh.
I will keep it in observation, but If this is true, not sure if it worth all this extra code.
For fun of course, I have enjoy a lot, but I love simple codes when possible…
Anyway, I have only one DW2 wifi which I will keep. Now with battery in % and this retain state, it is great. I have got another DW2 but RF which is going direct to garbage as it has no state, just send state when opening (now it is just in my desk to know when the kids ‘borrow’ my pens).
I have try the SonOff Zigbee SNZB-04 together the bridge and these are perfect. No issues to install. Never loose the state but they refresh their status enough quick enough in some seconds/minutes after a reset. Battery last 5 times the DW2 one and they are 3/4 of the size.
Sorry for the late answer, the documentation of alexxIT says that it is only in the cloud available.
In the main time I have connected to the cloud and directly after connect the DW2 is available.
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.
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%