Shelly Plug S Rule compare

Tags: #<Tag:0x00007f5c95a89ca8>

Hello all,

I have meanwhile a lot of TP-Link Power Plug’s in use. I can also switch off them,
based on rules via PaperUI and NG rules.

Now I want to do this also with my Shelly devices.
Normaly, to can compare values with each others, I change the item from the power values from the thing, that it is only a “number”. So my rules run with compare, e.g. when < 5.0, in this case fro “Watt” an then send a command to switch for power off.

I have tryed this in the same way with the power value from the shelly Plug S, without out been seccessfull. Run the ruke manuel works, but not with the condition, then for less the 5 Watt.

Does someone has a idea?

BR
Scheuerer

Please post the code you tried to write but didn’t work.

QuantityType

1 Like

OK, it’s a lot more useful to post actual code using How to use code fences than a screen shot.

What’s the definition of BroKellerSteckdosenleiste_Meter_currentWatts? Is it Number:Energy as rossko57 asked about? If so, the PaperUI generated Rules do not support Units of Measurement Items directly. You can use “a given script evaluates to true” with something like:

(items["BroKellerStechdosenleiste_Meter_currentWatts"].floatValue() > 5.0)

or even better since it respects the units

(items["BroKellerStechdosenleiste_Meter_currentWatts"] > new QuantityType(u"5.0  W"))

Thanks for the feedback.

I have now tryed both versions and also changed the Number:Energy in the case with the trail for compare with the settings in “W”.

But without scuccess:

Here is one one the two examples in the rules.

BR
Scheuerer

Might we actually see the Item definition as it is now?

Thanks for the feedback:

I have had two different version now:
Version one:
Item set only to Number, and

(items[“BroKellerSteckdosenleiste_Meter_currentWatts”].floatValue() > 5.0)

and the other version, with
Item set only to Number:Energy, and

(items[“BroKellerStechdosenleiste_Meter_currentWatts”] > new QuantityType(u"5.0 W"))

In the first case nothing happen in the log file in the secound see it like that
2020-05-20 16:45:09.340 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29645 s to 29690 s

2020-05-20 16:45:24.519 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29690 s to 29705 s

2020-05-20 16:45:39.427 [ome.event.ItemCommandEvent] - Item ‘BRoKellerSteckdosenleiste_Relay_Betrieb’ received command OFF

2020-05-20 16:45:39.431 [nt.ItemStatePredictedEvent] - BRoKellerSteckdosenleiste_Relay_Betrieb predicted to become OFF

2020-05-20 16:45:39.446 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Relay_Betrieb changed from ON to OFF

2020-05-20 16:45:39.685 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29705 s to 29721 s

2020-05-20 16:45:41.975 [ome.event.ItemCommandEvent] - Item ‘BRoKellerSteckdosenleiste_Relay_Betrieb’ received command ON

2020-05-20 16:45:41.979 [nt.ItemStatePredictedEvent] - BRoKellerSteckdosenleiste_Relay_Betrieb predicted to become ON

(items[“BroKellerSteckdosenleiste_Meter_currentWatts”] > new QuantityType(u"5.0 W"))

2020-05-20 16:45:42.005 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Relay_Betrieb changed from OFF to ON

(items[“BroKellerSteckdosenleiste_Meter_currentWatts”] > new QuantityType(u"5.0 W"))

2020-05-20 16:45:42.858 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29721 s to 29724 s

2020-05-20 16:45:46.030 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29724 s to 29727 s

2020-05-20 16:45:58.045 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Meter_currentWatts changed from NULL to 9.3 W

2020-05-20 16:45:58.213 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29727 s to 29739 s

2020-05-20 16:46:01.368 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29739 s to 29742 s

2020-05-20 16:46:01.375 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Meter_currentWatts changed from 9.3 W to 9.2 W

2020-05-20 16:46:03.056 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Meter_currentWatts changed from 9.2 W to 6.8 W

2020-05-20 16:46:04.081 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Meter_currentWatts changed from 6.8 W to 15.8 W

2020-05-20 16:46:05.607 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29742 s to 29746 s

2020-05-20 16:46:08.778 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29746 s to 29750 s

2020-05-20 16:46:08.790 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Meter_currentWatts changed from 15.8 W to 16.6 W

2020-05-20 16:46:17.065 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Meter_currentWatts changed from 16.6 W to 0.0 W

2020-05-20 16:46:17.961 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29750 s to 29759 s

2020-05-20 16:46:27.143 [vent.ItemStateChangedEvent] - BRoKellerSteckdosenleiste_Device_Laufzeit changed from 29759 s to 29768 s

Are you sure, thet the syntax in the secound case, e.g. with two spaces between 5.0 and W,
and thi “u” before 5.0 is correct?

The number of spaces is irrelevant but the u is probably not needed. It is needed in Python but may not be in JavaScript. Please read the post I linked to above about using code fences. Reading logs and JSON without that is almost impossible.

Boah eh, this was this time a hard one…

After having more that ten TP-Link HS110 Power Plug’s in use which work over the same logic in their OH 2.5 NG rules, so when the item get’s an update from the status (power off, on), send a comand to the item to switch it off, but only when the item (power) is less them 5 W.

So those run, and run, since couple of months.

But not the brand new Shelly Plug S.

Meanwile it work’s. and this also WITHOUT and scripts in the conditions “but, only if” in use.

Problem here was the start condition. So the “trigger” when is should work. As said before, bei TP-LINK i use the update from the switch ON, Item.

But in the Shelly case I need a other trigger.
I first tryed, with the livetime value as a trigger, but now irealy changedto the “power change value”.
So more less it works now in NG Rules like that:

When, the item “power energy” changes, send the “Power switch” the command “OFF”, but only, if the item “current energy” from the item is less than 5.

As usal also with all my other plugs, the item “current energy” need to be only a number, not a number+dimension.

YEAH, total happy for fathers day, to have my first Shelly Plug S running in this schema.

BR
Jochen