Energy meter rule causing smart plug to turn on off on off

Hello, I have the rule screen shot below. Hardware is C8 pro and smart plug is a Zigbee ThirdReality plug with engery meter. I have the smart plug named Power Station DJI 1000.

I have a rule when the power is 25watts or lower, to turn off the plug.
Intermittently when I turn on the plug manually, it would turn off right away instead of staying on. I only turn on when I need to charge the power station. When the 2pm rule runs, the plug turns on off on off on off right away. It doesn't matter if it's fully charged or not. Eventually it will stay on. Their has been rare times where it stays off.

I tried putting delays before turning it off but it stills acts up. I'm sure there's a much better way for creating the rule but I can't figure it out.

I would watch the power meter when the rules run, and see what the power attribute is doing. It may be fluctuating when you first turn on the power, over and under the 25 watts.

Battery chargers do fluctuate when they first get power by starting at a high current and then settling into the charging current depending on how depleted the battery is.

You can also test this by using a light bulb or something that would be more consistent in power usage, and see what the rules do.

I have not taken a close look at how all these interactions can potentially collide, but one thing that jumps out at me is that your rule Actions all result in rule Triggers...

I gotta think that's problematic here with creating race conditions or leading to some other kind of undesireable outcome.

I am thinking the same thing in regards turning on and it's already less than 25watts at first turns on. I can't figure out to put a delay before it reads the energy meter. Just putting a delay, only delays it from turning off.

It could be the triggers but I don't see anything obvious to that would cause it to turn off. I think I tried removing the trigger when power meter reads =< 25. I believe it doesn't turn off without that trigger.

My recommendation is to use two separate rules. One for turning On and second for turning Off. If you really want one single rule you should use "Else If" stament. Using sequence of "If" statements is not a good choice.

2 Likes

@HERON This :point_up:

Also consider making the trigger <= sticky, i.e. add the โ€œand staysโ€ for a minute or two. Might be useful for the illuminance condition too.

3 Likes

I assume that power level reports zero when the plug is off, and it takes a period of time before it reports a change.

When you turn on charger at 2pm it retriggers the rule immediately. The 2nd "If-Then" will then execute, and if the power level has not updated in that short time, (i.e. it is still reporting zero) , it will turn off the plug immediately.

I suggest limiting re-triggers (caused by an action) by setting a private boolean at the beginning and end of the actions, and making PB a condition for triggering.

In the 2pm If-Then, add a 5 second delay to let the power level stabilize, and add a nested If power <25 then turn off Charger. This is required to turn off the charger in case the power level is already below 25. Otherwise a drop to 25 later will never occur, and the rule will not re-trigger.

Of course I am assuming nested if-thens are permitted in Rule Machine

1 Like

Thanks for the suggestions. I thought about creating separate rules. As for private boolean, I have no idea how to set those up.

I looked into a 2nd if-then but I couldn't figure out what to add to the rule with the delay.

Before adding a separate off rule, I am trying waiting for expression. Not sure if this will work.

After further examination, I think I can explain the on-off-on cycling you desribed.

As mentioned before, your actions are causing the rule to be re-triggered many times.

For example when you turn on the charger the rule is re-triggered twice. First because it was turned on, and second because the power may have changed from 0 (off value) to a new value of <25.

When you turn off the charger the rule will re-trigger because the power changes from it's existing value to 0.(i.e. trigger when power <=25)

You can eliminate these self-re-triggers by using the PB method described in an earlier post, but even if you eliminate those triggers, your luminance sensor may be causing new triggers.

The problem may be the frequency of your luminance updates. It's conceivable that luminance levels could be fluctuating above 950 several times a minute (example 950-960-955). The result is that the rule could be triggering several times each minute. How often does your luminance level update? Check your logs at various times of the day to find out.

Your actions include 3 "If-Thens" that are limited to run at specific times.

#1 Sunrise to 10:30am
#2 10:31am to 8:00am the next day
#3 2:00-2:01pm

#1 & #2 overlap from sunrise to 8am, and #2 & #3 overlap from 2:00pm to 2:01pm

If the time is between sunrise and 8am, #1 will turn the power on, which in itself will re-trigger the rule, and if the power <=25, #2 will turn it off. When the luminance changes next time, the rule will re-trigger, and this on and off cycle will repeat.

If the time is 2pm, then #3 will turn on the power, which in itself will retrigger the rule, and if it changes from 0 to something <=25, then #2 will turn it off. This will repeat from 2:00pm to 2:01pm every time the luminance level changes.

I think it might be best to let us know your overall goal, and perhaps we can suggest a new approach.

1 Like

I believe you may be over-complicating things.

The two-rule route will yield the simplest result (and easiest to debug / iterate over).

Here's what that could look like:

RULE 1: turn on power station

  • Required expression: power station is off
  • Conditional trigger: illuminance of Front Motion >= 950 and stays for 2 minutes ONLY IF Time between sunrise and 10:30AM
  • Trigger: when time is 2:00PM
  • Action: turn on power station

RULE 2: turn off power station

  • Required expression: power station is on
  • Conditional trigger: power level of power station <= 25 and stays for 2 minutes ONLY IF time between 10:31AM and 8:00AM
  • Action: turn off power station

Here's what a conditional trigger with "stays" looks like:

I'm too lazy to build the whole rules for you but hopefully this is enough to get you going.

p.s. no need for "private boolean" if you go this route, the on/off state of the power station can serve as the required expression condition.

4 Likes

That look very clever. I have never used conditional triggers, so I have a question for you.

I believe that the OP's original trigger (illuminance of Front Motion >=950) would re-trigger the rule with every update from the sensor, as long as the reported levels were >=950.

Will your conditional trigger only run the actions once when the level reaches >=950 the first time? I.E. additional changes in illuminance will not re-trigger the rule? What happens if the illuminance never drops below 950? Will the trigger occur the next time the "time" requirement becomes true.

Thanks

Edit: I just realized your rule won't rerun because of the required expression =power off. But if that requirement didn't exist, how would you answer the question about repeat triggers with illuminance changes.

Thank you for the detailed explanation. I did fix the over lapping in between times as @user5298 mentioned. Although my latest change worked, it doesn't mean it will be consistent. I agree that with @hubitrep and others mentioning to create 2 rules. The Required expressions will make it more reliable.

Here's the explanation and what I am trying to do for this rule:

I use the Power station to power up certain devices starting at 4pm and run on batteries until the next day when my solar is generating enough power to run off solar power only. My peak PGE rates start at 4pm. I currently don't have dedicated batteries for my solar system. I am trying to learn so I can eventually add dedicated batteries.

I use the DJI PS on various electronic devices, I may use it multiple times in a day and want to do the finally charge at 2pm so it can be topped off before 4pm. It maybe a rainy day, at least I am powering off the grid when rates are it's lowest. My other power stations rules are easy as it runs on battery at 4pm and doesn't powers until running on solar power or at a certain time if a cloudy day. My network runs on one of these power stations. All my power stations start on different times depending on how much solar is being generated.

I over explained just incase some is trying to do the same setup. I'll probably never be completely off the grid but I come close and save money - eventually lol

Conditional triggers work the same way as ordinary triggers, so the rule will re-trigger if there is a new event >= 950 and the condition is satisfied - as long as the required expression is true. However, I did add a "stays" in there, which may or may not be needed, but that will change the behaviour of the rule somewhat as not every illuminance event >= 950 that satisfies the condition will actually fire the trigger (i.e. if it happens in the "stays" period).

In the end, because the only action is to turn the power station on (or off), none of this matters. This is the beauty of stateless rules (the state is held by the power station device itself, not the rule).

Yeah I actually wasn't trying to make the OP's rule work, rather provide a framework (broadly applicable btw) that the OP can use to set up whatever "reasons" (triggers) warrant turning the device on in one rule, and conversely.

It would be easy to add additional triggers and the result is much more readable (to me anyways) than a bunch of conditional actions.

3 Likes

Thank you for the explanation and the tips! I wish I can ask AI to create the rule I want lol.

I forgot to answer the question regarding the illuminance event. I know it looks confusing. To clarify I'll use the my latest changes. The 950 illum trigger happens only between 6:05 to 10:30am. There is no turn off trigger during this time frame. The turn off rule (<25) only runs between 10:30am to 6am.