I´m using a Sonoff Pow to measure the power consumption of my dryer in the basement. Actually I want to get an info when the dryer has finished his job. That would be the case when the power consumption is at 0. The problem I encountered is, that the dryer power consumption is falling to 0 after a while, obviously because it has a little break in it´s pogram (and a few more later), but then it continues drying. I need to create a rule that checks if it is just a break or if the program really has finished. I thought I could program a break after the first 0 power consumption, but to proceed I would need an updated Item status. Is this possible? Is there a better option to get what I want? Below you can find my actual rule without a break:
rule "dryer"
when
Item Pow2EnergyMon changed
then
{
if (Pow2EnergyMon.state > 300)
{
Notification2_Sent = 0
}
if (Pow2EnergyMon.state < 1)
{
if (Notification2_Sent == 1)
{
return false
}
else
{
sendNotification("xxx", "dryer finished!!")
Notification2_Sent = 1
}
}
}
end
rule "dryer"
when
Item Pow2EnergyMon changed
then
[..]
// check if power is 0 Watt
if (Pow2EnergyMon.state < 1) {
// wait for 30 seconds
Thread.sleep(30000)
// check againif power is still 0 Watt
if (Pow2EnergyMon.state < 1) {
sendNotification("xxx", "dryer finished!!")
} else {
// dryer is still running
}
ok, that´s what I planned to do, the question is what is saved in “.state”. Is it pulled from the device in the moment it gets called or is it only delivered when Item Pow2EnergyMon changed is called? If that´s the case the value would be the same on the second call of “.state”…
Item’s only represent the last reported state. It doesn’t go out and get the latest value from the device when you call Pow2EneryMon.state, largely because there are very few technologies that would support that.
The stuff between the when and then define the events that take place to trigger the Rule. As written above, the “dryer” Rule only runs when Pow2EneryMon changes state.
It is theoretically possible if while the Rule is running Pow2EnergyMon changes its state that the second call could have the new state. In practice, you would have to include a Thread::sleep or other long running call between the two accesses of the Items state for that to actually ever occur.
And the Sonoff is probably reporting this value once every several seconds at the fastest so that problem will never practically ever occur.
I’d say try it and see. It looks like it should work, though it is not a good way to implement it because of the long Thread::sleep, which can cause problems.
I would do something like the following:
New Item:
Switch Dryer { expire="30s,command=OFF" } // send an OFF 30 seconds after the last time an ON update is received
Rules:
rule "Dryer on"
when
Item Pow2EnergyMon changed
then
if(Pow2EnergyMon.state == NULL) return;
if(Pow2EnergyMon.state >= 1) Dryer.sendCommand(ON)
end
rule "Dryer off"
when
Item Dryer received command OFF
then
sendNotification("xxx", "dryer finished!")
end