Shelly binding NG rule based on less the 5 Watt power

Hello all,

I have no idea anymore what to do.
There is a need to switch off my shelly 2.5 via OH 2.5 over a rule which was done via NG rules UI, if the power which is messured is less that 5 Watt.

I have now tried all kind of combinations.

  • 5.0
  • 5,0
  • 5.0 W
  • 5,0 W
    an all the above value with " " e. g. “5.0 W”

Has someone experience with rules and compare values e.g. power off by less the x.y Watt.

Thanks for all the Tipps.
BR
Scheuerer

It’d be a whole lot more helpful if you posted where you are entering the 5.0. In the trigger? In the “but only if…”? In the Script Action? Which programming language?

Hello Rich,

thanks for this good questions.
The rules have neen generated with the NG editor unter PaperUI on an 2.5.3-1 PI system.

###############################################################################
############### openhab #####################################################
###############################################################################

Ip = 192.168.1.9

Release = Raspbian GNU/Linux 10 (buster)

Kernel = Linux 4.19.97-v7+

Platform = Raspberry Pi 3 Model B Plus Rev 1.3

Uptime = 1 day(s). 4:14:52

CPU Usage = 5.2% avg over 4 cpu(s) (4 core(s) x 1 socket(s))

CPU Load = 1m: 0.41, 5m: 0.31, 15m: 0.22

Memory = Free: 0.16GB (17%), Used: 0.78GB (83%), Total: 0.95GB

Swap = Free: 0.09GB (100%), Used: 0.00GB (0%), Total: 0.09GB

Root = Free: 10.43GB (76%), Used: 3.27GB (24%), Total: 14.32GB

Updates = 5 apt updates available.

Sessions = 1 session(s)

Processes = 109 running processes of 32768 maximum processes

###############################################################################

          Welcome to            __  _____    ____  _
        ____  ____  ___  ____  / / / /   |  / __ )(_)___ _____
       / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  / / __ `/ __ \
      / /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ / / /_/ / / / /
      \____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/_/\__,_/_/ /_/
          /_/
              openHAB 2.5.3-1 (Release Build)

The log filelooks like this:

2020-04-10 17:10:31.165 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_Strom changed from 67.680 W to 67.730 W

2020-04-10 17:10:31.182 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_LetzteAktualisierung changed from 2020-04-10T17:10:19.000+0200 to 2020-04-10T17:10:31.000+0200

2020-04-10 17:10:31.207 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1377 s to 1389 s

2020-04-10 17:10:43.463 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_Strom changed from 67.730 W to 0.000 W

2020-04-10 17:10:43.487 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_LetzteAktualisierung changed from 2020-04-10T17:10:31.000+0200 to 2020-04-10T17:10:44.000+0200

2020-04-10 17:10:43.507 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1389 s to 1401 s

2020-04-10 17:10:49.772 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1401 s to 1408 s

2020-04-10 17:11:14.073 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_Gesamtverbrauch changed from 0.0088 kWh to 0.0096 kWh

2020-04-10 17:11:14.110 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_SchnitteLetzteMin changed from 17.337 W to 47.366 W

2020-04-10 17:11:14.115 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_SchnittVorletzteMin changed from 0.000 W to 17.337 W

2020-04-10 17:11:14.117 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_SchnittVor3Min changed from 5.407 W to 0.000 W

2020-04-10 17:11:14.119 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_LetzteAktualisierung changed from 2020-04-10T17:10:44.000+0200 to 2020-04-10T17:11:14.000+0200

2020-04-10 17:11:14.121 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1408 s to 1432 s

2020-04-10 17:11:20.817 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1432 s to 1439 s

2020-04-10 17:11:27.066 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1439 s to 1445 s

2020-04-10 17:11:42.352 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1445 s to 1460 s

2020-04-10 17:11:51.635 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1460 s to 1469 s

2020-04-10 17:11:57.963 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1469 s to 1476 s

2020-04-10 17:12:13.233 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_SchnitteLetzteMin changed from 47.366 W to 0.000 W

2020-04-10 17:12:13.263 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_SchnittVorletzteMin changed from 17.337 W to 47.366 W

2020-04-10 17:12:13.278 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_SchnittVor3Min changed from 0.000 W to 17.337 W

2020-04-10 17:12:13.285 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Meter1_LetzteAktualisierung changed from 2020-04-10T17:11:14.000+0200 to 2020-04-10T17:12:13.000+0200

2020-04-10 17:12:13.289 [vent.ItemStateChangedEvent] - Shelly25RelaySHSW25_Device_Laufzeit changed from 1476 s to 1491 s

The rule in the automation_rules.json file under /var/lib/openhab2/jsondb looks like this:

“85c6228a-ed58-4f90-94c1-92b3abc00d03”: {
“class”: “org.openhab.core.automation.dto.RuleDTO”,
“value”: {
“triggers”: [
{
“id”: “1”,
“label”: “an item state is updated”,
“description”: “This triggers the rule if an item state is updated (even if it does not change).”,
“configuration”: {
“itemName”: “Shelly25RelaySHSW25_Relay1_Betrieb”,
“state”: “ON”
},
“type”: “core.ItemStateUpdateTrigger”
}
],
“conditions”: [
{
“inputs”: {},
“id”: “3”,
“label”: “an item has a given state”,
“description”: “Compares the item state with the given value”,
“configuration”: {
“itemName”: “Shelly25RelaySHSW25_Meter1_Strom”,
“state”: 5.0,
“operator”: “\u003c”
},
“type”: “core.ItemStateCondition”
}
],
“actions”: [
{
“inputs”: {},
“id”: “2”,
“label”: “send a command”,
“description”: “Sends a command to a specified item.”,
“configuration”: {
“itemName”: “Shelly25RelaySHSW25_Relay1_Betrieb”,
“command”: “OFF”
},
“type”: “core.ItemCommandAction”
}
],
“configuration”: {},
“configDescriptions”: [],
“uid”: “85c6228a-ed58-4f90-94c1-92b3abc00d03”,
“name”: “TEST Shelly 2.5”,
“tags”: [],
“visibility”: “VISIBLE”,
“description”: “TEST Shelly 2.5”
}
},

The screenshots from the rules values are added.

Shelly2.5_3 Shelly2.5_2 Shelly2.5_1

I hope I have now added all information that is needed to brinf to rule ti run :slight_smile:

BR & Thanks
Scheuerer

First of all please How to use code fences. JSON is hard enough to read already without all the spacing getting messed up.

I am pretty certain that PaperUI cannot handle Units of Measurement in that way. You will have to do it in code. For the “but only if…” section use “a script evaluates to true” and use code along the lines of

(event.itemState < new QuantityType("5.0 W"))

I’m not wholly certain I have everything right with that. You might need to pull in QuantityType to use it like that. Try it and see what happens.

Hello Rich,

as I have had a solution in place for this, your idea with a secript is only my secound plan.
I found the root case, I tell you.
The problem was, that the item has had “power” under Dimension.
When I delete the Dimension, and have only number (see booth screens) I’m able to compare values and the rule is working again.

So problem is now solved.

Br
Jochen


Exactly, that “power” makes the Item be a QuantityType, i.e. it uses Units of Measurement.

NOTE that many bindings require the dimension so your solution only works in this case because the source binding does not require the dimensions.