Is there a better way to write this Rule?

I've written a rule to turn on a space heater if the temp is equal to or below 67℉. I'm using a Smartthing motion/temp sensor and an Aotec plug to verify a person is in the heated space, and the temp is low enough to turn on the heater.

The rule works just fine. However, when I look at the logs, the rule is triggering every minute or so. The way I've written the script doesn't appear to be efficient. What is a better way to approach this action? I'm new enough at this that I'm at a loss to make this rule more efficient.

I think the trigger event will need to be a changed there, because it won't trigger for an inactive, but you'll also want a delay there so that it doesn't turn off if you're sitting still. :grin:

1 Like

The rule is being triggered every time motion is detected. Depending on your motion sensors timeout; it could be as short as 30 seconds or so. I would recommend you setup a 'motion zone controller' with a high activity timeout setting. I would also set the trigger to changed.

1 Like

How and where would you add a delay? Is that the same as a timeout?

Adding a delay is different than the timeout of the motion sensors. You can certainly add a delay to the rule but adding a motion zone via the built in motion zone app will give you more control for this rule. It will allow you to easily change the timeout, instead of having to edit the rule, as well as setting up motion aggregation if you ever wanted to use more than one motion sensor in that area.

Just my two cents.

2 Likes

Change your trigger to the temperature changes. Then you can set ranges so that it's not triggering so often. I have a rule on my bedroom fan that covers that. It's not perfect, I'm sure, but It works for us. this turn of the fan when mode changes to home because we would not be in bed. Hope this sparks some ideas for you. Your way isn't wrong. Mine isn't right or the only way either. Just an example of what I do to help control temperature in the room.

1 Like

I agree a motion zone will result in simpler RM code. Bear with me this is an event driven solution which looks different than the more procedure solution most people are used to.

You would select Day and Evening in your case. Also you aggregate with only one motion sensor.

I find setting the device timeout to 1 minute and the motion zone to 5 minute works well.

Now you need a Rule to receive the motion event.

The action are:
If temperature <= 68 then
. turn plug on
Endif

Another rule to turn off the plug:

This trigger catches the inactive events for 3 zone inactive events, yours needs to capture your single zone.
The action would be:
off plug

Finally for safety you could add another rule:
Trigger: Temperature Peters office > 69
Action: Off plug

I would recommend there be a few degrees between plug on (67) and plug off (69) in order to prevent creating an oscillation between the plug turning on and off.

2 Likes

Great suggestion. I’ll try it out this evening.

For a heater maybe you should increase the activity time out. Maybe 10 or 15 minutes. Every time the motion sensor is triggered during the 10 minutes it resets the time out to start again. This should keep the heater on while you are present.