Soo, I came across with another sample ideia that works. Soo this topic can be close
Configuration.yaml
sensor:
platform: sql
db_url: !secret db_url
queries:
name: Sonoff_GetastState
query: >
SELECT state
FROM “states”
WHERE entity_id like ‘%sonof%’
AND state NOT IN ( ‘unavailable’, ‘unknown’)
ORDER BY Last_Updated desc
LIMIT 1;
column: ‘state’
How did you manage to get DW2 WiFi working with HA, was it via HACS or some other way? I did pair with eWeLink, DW2 is now connected to my wifi, I know its IP address. But no idea how I can make it working.
Could you please advise?
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.