My TV is plugged into a Shelly plug-S.
My receiver is plugged into a separate Shelly plug-S
When my TV goes to standby (<10watts) it needs to turn off the receiver and the other way around.
This works of course but now and again my TV boots up in the background (when in stand-by) and goes to 80watt for 2seconds, so turning on the receiver.
When the TV is on but only showing blacks, it draws 40watt so I cant use this threshold since it then turns off the receiver during a dark scene.
When the wattage goes >10watts I need it to wait for a certain amount of time, check the wattage again, and only then turn on the receiver (and the other way around ofcourse).
Like a (delay) or timer function.
I searched and tried for ages but have no clue how to work with timers in openHab.
Wish it was as easy as “blink without delay”
Hope you can help me out, thanks again for your time
First choice you need to make is what rules system you prefer in OH3. No point in showing you hundreds of DSL examples in this forum if you want to use Groovy or Blockly.
Use blockly, create a timer e g. For 2 minutes and inside the time add the code that should be executed after 2 minutes (e.g. checking the current energy consumption or using persistence service to get min/max/avg watt of the last 2 min)
I have made something similar, where I monitor the power consumption of a charger and have it switch off when the power consumption drops below a certain wattage.
I made 1 helper (Tasmota41128EChargingWatchdog) item with an expiration timer of 3 minutes and command = OFF. This item is first switched ON through a rule at the same time as the Tasmota switch is switched on.
I have a second rule that is triggered when this helper item is switched off (I.e. after 3 minutes). The code for that rule is below.
var item=items.getItem("Tasmota41128E_Power");
var timeInterval = 3;
var timeElapsed = time.ZonedDateTime.now() - (timeInterval * 60);
var minimumWattage = 4
if ((item.history.averageSince(time.ZonedDateTime.now().minusSeconds(180))) < minimumWattage ) {
items.getItem("Tasmota41128E_State").sendCommand("OFF")
} else {
items.getItem("Tasmota41128EChargingWatchdog").sendCommand("ON")
}
//below gets the historical sate if an item
var PersistenceExtensions = Java.type("org.openhab.core.persistence.extensions.PersistenceExtensions");
var ZonedDateTime = Java.type("java.time.ZonedDateTime");
var myPersistentItem = ir.getItem("Zigbeesengledbulb_Zigbeesengledbulb");
logger.info("The pyload is {}", myPersistentItem);
var sinceDate = ZonedDateTime.now().minusDays(7);
//var sinceDate = ZonedDateTime.now().minusHours(5);
var maximumValueSince = PersistenceExtensions.maximumSince(myPersistentItem, sinceDate);
logger.info("Historic item is {}", maximumValueSince);
logger.info("Item name is {}", maximumValueSince.name);
logger.info("Item state is {}", maximumValueSince.state);
You might already be aware of this: they sell a power strip that has “Master / Slave” thing. When the load on the Master is low, it turns off the slave outlets.
Example (and there are many out there): Amazon.com
Anyway, for your original question, it can be implemented in jruby like this:
require 'openhab'
LOW_POWER = 0|'W'...10|'W'
HIGH_POWER = 10|'W'..
rule 'Turn on the receiver' do
changed TV_PowerDraw, from: LOW_POWER, to: HIGH_POWER, for: 5.seconds
run { Receiver_Power.ensure.on }
end
rule 'Turn off the receiver' do
changed TV_PowerDraw, from: HIGH_POWER, to: LOW_POWER, for: 2.minutes
run { Receiver_Power.ensure.off }
end
The for: argument above ensures that the rule only executes if the item’s state remains in the to state for the specified duration. You won’t need to manually create your own timer to keep track of it.
The ensure will not send the on/off command if the item is already in that state.