# Rule to issue commands based on upper and lower temps

**URL:** <https://community.openhab.org/t/rule-to-issue-commands-based-on-upper-and-lower-temps/29284>\
**Category:** Beginners\
**Tags:** rules, ecobee, 433mhz\
**Created:** [June 1, 2017, 9:32am UTC](https://community.openhab.org/t/rule-to-issue-commands-based-on-upper-and-lower-temps/29284 "2017-06-01T09:32:07Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [June 2, 2017, 2:14am UTC](https://community.openhab.org/t/rule-to-issue-commands-based-on-upper-and-lower-temps/29284/3 "2017-06-02T02:14:55Z")

</div>

> [@hotterpop](#):
>
> This doesn’t account for sending the shutoff code if the occupancy changes to OFF and the temperature is still above 73.

Use

```
when
    Item kidsroomOccupancy changed Or
    kidsroomTemperature changed
then

```

to trigger your rule. That way the rule gets triggered whenever the temperature or the occupancy changes and you can calculate the proper state of the heater.

> [@hotterpop](#):
>
> At present, this rule is (I think) constantly going to be applied, which means that if the room occupancy is ON, the radio will constantly be in use either sending the turn off or turn on code. I need a way to remember the last state of the AC unit (like a variable to store on or off) and not send the code if the state doesn’t need to be changed. I’m not sure how to store variables or do AND statements as part of an if statement’s conditions.

Incorrect. Rule triggers are event based, not state based. The rule runs when certain events occur, not while Items are in a certain state. The trigger you are attempting to use is invalid

That being said, you can do a simple check like the following:

```
if(kidsroomTemperature.state > 77 && kidsroomHeater.state != ON) {
    kidsroomHeater.sendCommand(ON)
}
...

```

Note how I’m using an Item above instead of executeCommandLine. You should have a Switch Item to represent the state of your heater/airconditioner and when this Item is set to ON make the call to executeCommandLine.

See:

> [@Design Pattern: Proxy Item](https://community.openhab.org/t/design-pattern-proxy-item/15991):
>
> Edit: Updates for OH 4 Please see [Design Pattern: What is a Design Pattern and How Do I Use Them](https://community.openhab.org/t/design-pattern-what-is-a-design-pattern-and-how-do-i-use-them/40319) for information on what a DP is and how to use them. Problem Statement Often one faces one or more of the following situations: perform additional logic before sending a command to a device (e.g. make sure the device can safely receive the command) send a command to multiple devices based on a single event and Groups, the follow profile, or linking multiple Channels to one Item is not feasible t…

> [@hotterpop](#):
>
> I also have the switch, item KidsAC, to manually turn on the AC unit. It would be great if when the AC is turned on by this rule, it updates the state of the switch to be on or off. Rather than using the same executeCommandLine bit I have in thee above logic, should I instead be using KidsAC.sendCommand(OFF) or (ON)? I’m not sure how this function works.

Again see the Proxy Design pattern. Essentially you want to represent the state of the air conditioner using a SwitchItem. Then have rules to interact with the other Items and translate commands to the Proxy Item into commands to the device (i.e. your calls to executeCommandLine) and translates changes to KidsAC into updates to the proxy item.

---

_[View the full topic](https://community.openhab.org/t/rule-to-issue-commands-based-on-upper-and-lower-temps/29284)._
