Goal: I am using another Rpi3+ as Kodi Media-Player, which is connected to openhab as a thing. It is plugged into a Devolo Smart Plug 2 (Manual). The Smart Plug is capable of metering the actual power consumption and reporting it. I set the reporting period (parameter 1) to 3min. By turning on the power outlet, I make the Kodi-Player start the boot process. Therefore, it is necessary to turn off the power after shutting down the Kodi-Player so that it is ready to start a new boot process next time.
That’s why I want to create a rule which shuts down the power outlet of the smart plug after 5 minutes, if the average of power consumption reported was lower than 3 Watts. The calculation of the average power consumption over 5 min is necessary and can not be changed to only a single measuring point, because the RPi sometimes has fluctuations in power consumption or needs to be restarted without the power being cut off.
Therefore, I started with setting up persistence (rrd4j) for the smart plug.
Problems:
Even though I changed the reporting period in the Device Settings to 3min, I only get reports every hour (see logs below). That’s why I guess something is misconfigured with the persistence or I need to somehow tell openhab to get the actual power consumption in the right interval.
Can someone tell me how to do this?
Even if the change in power consumption is recorded once every hour, my rule seems not to trigger a switch of the power outlet. I see one problem: If the item measuring the power consumption changes and I use this event as a trigger to calculate the average consumption over the last minutes, the outcome will most probably be over the 3 Watts, because the RPi just turned off. But I have no idea to avoid this problem. Maybe with a timer triggered first?
Rules code related to the issue:
kodi.rules
rule “Kodi Stromzufuhr abschalten wenn ungenutzt”
when
Item Verbrauch_Kodi changed
then
// Add persistence to Verbrauch_Kodi item
if(Verbrauch_Kodi.averageSince(now.minusMinutes(10)) > 2){ // adjust time (1st) and watts (after >) as needed
// Thread::sleep(1000) // un-comment if needed to allow switch state to update
}
else if(Verbrauch_Kodi.averageSince(now.minusMinutes(10)) < 3){
Kodi_Energiezufuhr.sendCommand(OFF) // turn power off if kodi used less than XW in next X minutes
}
end
rule “Fernsehathmosphäre abends gemütlich, wenn Kodi an”
when
Item Kodi_Energiezufuhr changed from OFF
then
var Number hour = now.getHourOfDay
if ((hour >= 19) || (hour < 7 )) { // either its later than X OR earlier than X
sendCommand(KrakeImWohnzimmer_Helligkeit, 30)
}
end
If logs where generated please post these here using code fences:
I would be very happy for support for both problems or one of them.
The configuration parameter. I changed it already in the zwave device configuration.
I am not sure if I found what you are asking for. The deviceType is Binary Power Switch. The node ID is 2.
Which logs do you mean exactly?
This is cat /var/log/openhab2/events.log | grep Kodi for today.
2020-04-27 00:22:50.278 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 3.9 to 0.8
2020-04-27 02:22:50.925 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0.8 to 0.9
2020-04-27 03:22:51.196 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0.9 to 0.8
2020-04-27 06:22:52.199 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0.8 to 0.9
2020-04-27 07:22:52.483 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0.9 to 0.8
2020-04-27 08:22:52.821 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0.8 to 0.9
2020-04-27 10:22:53.430 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0.9 to 0.8
2020-04-27 10:52:42.318 [ome.event.ItemCommandEvent] - Item 'Kodi_Energiezufuhr' received command OFF
2020-04-27 10:52:42.328 [vent.ItemStateChangedEvent] - Kodi_Energiezufuhr changed from ON to OFF
2020-04-27 10:52:48.377 [ome.event.ItemCommandEvent] - Item 'Kodi_Energiezufuhr' received command ON
2020-04-27 10:52:48.390 [vent.ItemStateChangedEvent] - Kodi_Energiezufuhr changed from OFF to ON
2020-04-27 11:22:53.804 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0.8 to 3.9
2020-04-27 11:29:00.333 [temChannelLinkRemovedEvent] - Link 'Kodi_Energiezufuhr => zway:zwayDevice:192_168_178_32:2:switchPowerOutlet-ZWayVDev_zway_2-0-37' has been removed.
2020-04-27 11:29:00.336 [temChannelLinkRemovedEvent] - Link 'Kodi_FavoritAbspielenOderFfnen => kodi:kodi:fbf9b143-2783-0c91-2dac-b91681ca9338:playfavorite' has been removed.
2020-04-27 11:29:00.339 [temChannelLinkRemovedEvent] - Link 'Verbrauch_Kodi => zway:zwayDevice:192_168_178_32:2:sensorMeterW-ZWayVDev_zway_2-0-50-2' has been removed.
2020-04-27 11:30:00.434 [vent.ItemStateChangedEvent] - Kodi_FavoritAbspielenOderFfnen changed from NULL to UNDEF
2020-04-27 11:30:04.743 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from NULL to 3.9
2020-04-27 11:30:11.160 [vent.ItemStateChangedEvent] - Kodi_Energiezufuhr changed from NULL to ON
2020-04-27 12:30:11.719 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 3.9 to 0.8
2020-04-27 13:18:21.389 [ome.event.ItemCommandEvent] - Item 'Kodi_Energiezufuhr' received command OFF
2020-04-27 13:18:21.402 [vent.ItemStateChangedEvent] - Kodi_Energiezufuhr changed from ON to OFF
2020-04-27 13:18:26.287 [ome.event.ItemCommandEvent] - Item 'Kodi_Energiezufuhr' received command ON
2020-04-27 13:18:26.307 [vent.ItemStateChangedEvent] - Kodi_Energiezufuhr changed from OFF to ON
2020-04-27 13:30:12.118 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0.8 to 4.7
2020-04-27 14:30:12.589 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 4.7 to 0.8
2020-04-27 15:32:56.369 [ome.event.ItemCommandEvent] - Item 'Kodi_Energiezufuhr' received command OFF
2020-04-27 15:32:56.408 [vent.ItemStateChangedEvent] - Kodi_Energiezufuhr changed from ON to OFF
2020-04-27 16:30:13.591 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0.8 to 0
2020-04-27 16:30:13.631 [ome.event.ItemCommandEvent] - Item 'Kodi_Energiezufuhr' received command OFF
2020-04-27 17:45:17.954 [ome.event.ItemCommandEvent] - Item 'Kodi_Energiezufuhr' received command ON
2020-04-27 17:45:17.963 [vent.ItemStateChangedEvent] - Kodi_Energiezufuhr changed from OFF to ON
2020-04-27 18:30:14.407 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 0 to 3.9
2020-04-27 18:30:14.445 [ome.event.ItemCommandEvent] - Item 'Kodi_Energiezufuhr' received command OFF
2020-04-27 18:30:14.455 [vent.ItemStateChangedEvent] - Kodi_Energiezufuhr changed from ON to OFF
2020-04-27 19:30:14.742 [vent.ItemStateChangedEvent] - Verbrauch_Kodi changed from 3.9 to 0
2020-04-27 21:24:25.474 [ome.event.ItemCommandEvent] - Item 'Kodi_Energiezufuhr' received command ON
2020-04-27 21:24:25.509 [vent.ItemStateChangedEvent] - Kodi_Energiezufuhr changed from OFF to ON
Thank you. I had it in there before and added it again.
Using Habmin, Paper UI, or another zwave tool? Either way, it did not update if the device is still reporting every 1h. Debug logs for the binding will show a lot and may explain why it did not update. The reason you see the update every hour is due to the device being polled by the binding (default poll is 1h).
No, Habmin> Configuration> Things> select your Thing> Attributes> Type:ID…
Ah… you are using Z-Wave.me! I have no first hand experience with that and you will need to contact their support. I thought you were using the Z-Wave binding, which reportedly works much better than Z-Wave.me.
As from my noobish understanding I thought it obligatory to install z-wave.me to get the RaZberry Device running I am using to connect to my Z-Wave devices.
In openhab I also have the zwave binding installed. And it looks like the Plug in question is used through the binding as it’s address is zway:zwayDevice:192_168_178_32:2:switchPowerOutlet-ZWayVDev_zway_2-0-37
To be honest now I do not know if I should uninstall one or how to continue.
I had to remove it and add it again, and now: Yes! Thank you!
But now of course it becomes clear, that my rule is a desaster.
If the power consumption changes and in the same moment I want to calculate the average power consumption over the last ten minutes of course this number is below any threshold because the media player just started.
Is it possible to use: if(Verbrauch_Kodi.averageSince(now.plusMinutes(10)) > 2)
Instead of minusMinutes in this situation? I guess no because persistence has no numbers for the future, only for the past.
So what would be the best attempt here? Put a timer to wait for 10 minutes after a change in powerconsumption?
The usual approach, which you will find talked about here in the context of monitoring e.g. washing machine cycle, would be to detect when power has reduced to below a threshold.
By implication, the interest in the past when power changes is therefore “was it just working?” and so maybe it’s now stopped.
At that point you might start a timer, or count some more below-threshold reports, before deciding that yes it really has stopped.
That’s what I want to achieve. How do I count more reports for let’s say 10 more minutes, before deciding to switch off the plug?
As mentioned I want to make sure the Mediaplayer had really shut down and not only performed e restart or had a fluctuation in Power Consumption. Therefore, the trigger should be a reduced power consumption as in my rule example. But instead of immediately shutting it down if consumption is below the threshold of 3 Watts, I want the rule to check for 10 minutes after the initial loss in power consumption (trigger) if the consumption stayed below the threshold. How can I achieve this?
If power below threshold -
If your timer already exists, do nothing
Otherwise, make a new timer.
The timer is scheduled for ten minutes time to do your “off” actions.
If power above threshold, cancel any existing timer.
I guess that is your instantaneous power measurement Item?
It’s the .state you are interested in.
Be careful about what you compare it with, if your Item has UoM units.
You don’t need the persistence/average; if the reading rises above threshold it cancels the timer.
If it hasn’t done that in ten minutes, it commands OFF.
Use a unique name for your timer handle variable, so that you don’t accidentally introduce a clash when you write some other timer-using rule later.
Don’t forget to declare it in global namespace.