Simple temperature control

This is just a short post where I will show how I got my items, sitemap and rules for some simple temperature control.

Items

In items, I got a total of six items, one for temperature, one for heat index, one for humidity, one for the temperature target I am aiming for, and one for changing the mode.

The items with temperature, heat index and humidity should be self explaining, and the temperature target pretty much so too. But the control one might need a bit of explaining. This will be used to change between the modes On/Off/Auto, so it is easy to change between manual control and automatic.

Last we got the switch for the actual heater.

Notice

This is not a copy/paste example that will just work out of the box. The items below haven’t got anything defined about how they get updated with temperature and such, you need to add that yourself, as it is dependent on how you do it in your setup.

Number workroomTemp "Temperature [%.1f C]" <temperature> (Workroom)
Number workroomHeatIndex "Heat Index [%.1f C]" <temperature> (Workroom)
Number workroomHumi "Humidity [%.1f %%]" <humidity> (Workroom)

Number workroomTempTarget "Temperature target [%.1f C]" <temperature> (Workroom)

String workroomTempControl "Mode" <switch> (Workroom)

Switch switchWorkroomHeater "Heater" <switch> (Workroom)

Sitemap

Next we need some buttons to press, and this is where we need our sitemap.

This will show the temperature, and if the control is set to Auto, it will also show the temperature target.

At the end of the Temp Control switch, you can see “mappings”, this will give us the On/Off/Auto buttons. Pay attention to the number in front of the labels, we need those in the rules. So if we press Auto, the switch will be set to 2.

sitemap nygade label="Heat control"
{
	Frame label="Workroom"
	{
		Text item=workroomTemp
		Text item=workroomTempTarget visibility=[workroomTempControl=="2"]
		Text item=switchWorkroomHeater label="Heater" icon="fire"

		Switch item=workroomTempControl mappings=[1="On", 0="Off", 2="Auto"]
	}
}

And if everything goes as planned, it should look something like this.

2016-04-03 07.22.34 2016-04-03 07.22.41

Rules

And last, to make it all tick, we need a few rules.

The first one “Work room heat control” is the one doing the temperature comparison and will be triggered every time the temperature is being updated, and it is as simple as it gets. If the control mode is set to “2”, which means Auto, then continue to check if current temperature is above or equal to the target, and if the heater is on, then turn it off, the temperature is below the target, and the heater is off, then turn it on.

The next will be triggered by the control mode changing, so every time you change between On/Off/Auto, this rule will be triggered and if Auto is selected, it will update the temperature with the temperature it already got. This might sound strange, but remember, the rule deciding if the heater should be on or off, is triggered by the temperature getting updated. Setting the temperature, even to the same again, will trigger the rule, and immediately turn the heater on or off, depending on the target and the last reported temperature. If we didn’t do this, it would first change the state on the heater next time the temperature logging device reported the temperature.

The last rule is almost doing the same thing with setting the temperature, to the temperature we already got, but this is for the target instead of the mode. This rule will be triggered when the temperature target is changing, and if the temperature control is set to Auto, it will set the temperature again, and trigger the heat control so the heater will be changed accordingly to the temperature and target.

rule "Work room heat control"
when
	Item workroomTemp received update
then
	var Number setValue = workroomTemp.state as Number
	var Number tarValue = workroomTempTarget.state as Number
	
	if (workroomTempControl.state.toString == "2")
	{
		if (setValue.floatValue >= tarValue.floatValue)
		{
			if (switchWorkroomHeater.state == ON)
			{
				sendCommand(switchWorkroomHeater, OFF)
			}
		}
		else
		{
			if (switchWorkroomHeater.state == OFF)
			{
				sendCommand(switchWorkroomHeater, ON)
			}
		}
	}
end

rule "Work room heat control changed"
when
	Item workroomTempControl received command
then
	if (receivedCommand.toString == "1")
	{
		sendCommand(switchWorkroomHeater, ON)
	}
	else if (receivedCommand.toString == "0")
	{
		sendCommand(switchWorkroomHeater, OFF)
	}
	else if (receivedCommand.toString == "2")
	{
		postUpdate(workroomTemp, workroomTemp.state)
	}
end

rule "Work room heat target changed"
when
	Item workroomTempTarget received command
then
	if (workroomTempControl.state.toString == "2")
	{
		postUpdate(workroomTemp, workroomTemp.state)
	}
end

Leave a Reply