Rules With DS18B20 Temperature Sensor Fahrenheit

  • Platform information: openHAB 2.5.0 Build #1548

    • Hardware: Raspberry Pi Zero W / 16 gb SD card
    • OS: Raspbian 9 Stretch
    • Java Runtime Environment: Java 8
    • openHAB version: openHAB 2.5.0 Build #1548
  • Issue of the topic:
    When reading DS18B20 Temperature sensors with Onewire (OWFS), the sensors return Celciuis readings. I would like to display their readings in Fahrenheit, if possible. I can read them in Fahrenheit but my rules don’t work properly. (The items listed below are configured for reading them in Fahrenheit.)

I have my locale in raspi-config set to EN_US.UTF-8 UTF-8.

What am I missing? Thanks!

  • Please post configurations (if applicable):

    • Items configuration related to the issue
// This is the items file

//Relays
Switch GPIO_LAMP "Pump Relay" { gpio="pin:18 force:yes" }


//OneWire


//Temperature sensor

Number.Temperature      SP    "Solar Panel [%.1f °F]"     <temperature>        { channel="onewire:basic:7da51992:SP:temperature" }
Number.Temperature      HWT   "Hot Water Temp [%.1f °F]"  <temperature>        { channel="onewire:basic:7da51992:HWT:temperature" }
Number.Temperature      OT    "Outside Temp [%.1f °F]"    <temperature>        { channel="onewire:basic:7da51992:OT:temperature" }
  • Sitemap configuration related to the issue
sitemap home label="Gill's Guide Control Center"
{
	Frame label="Solar Panel UI"
	{
//		Switch item=channel1
		Text item=SP
		Text item=HWT
		Text item=OT
		Switch item=GPIO_LAMP
	}
}
  • Rules code related to the issue
rule "Solar Panel Charged And Ready / Pump On"
when
	Item SP changed
then
		var SP_Temp = SP.state as Number	
		var HWT_Temp = HWT.state as Number
	if (SP_Temp > (HWT_Temp + 10)) {
		GPIO_LAMP.sendCommand(ON)}
	else if (SP_Temp < 33)
		GPIO_LAMP.sendCommand(OFF)
	}End if 
Number.Temperature SP "Solar Panel [%.1f °F]" &lt;temperature&gt; { channel="onewire:basic:7da51992:SP:temperature" } 
Number.Temperature HWT "Hot Water Temp [%.1f °F]" &lt;temperature&gt; { channel="onewire:basic:7da51992:HWT:temperature" } 
Number.Temperature OT "Outside Temp [%.1f °F]" &lt;temperature&gt; { channel="onewire:basic:7da51992:OT:temperature" }

Try

Number:Temperature

I updated the items file to the Number:Temperature format. This displays the temperatures in Fahrenheit but my rule does not run.

Where do I find the rule logs?

Thanks!

Since these items are of type QuantityType, you need to extract the Number part.

Try this

var SP_Temp = (SP.state as QuantityType<Number>).intValue 
var HWT_Temp = (HWT.state as QuantityType<Number>).intValue

@mhilbush
I tried changing my variables to match this with no luck.

var SP_Temp = (SP.state as QuantityType<Number>).intValue
var HWT_Temp = (HWT.state as QuantityType<Number>).intValue

I get an error in the Openhab.log file that says:

2019-03-05 14:48:20.005 [WARN ] [.internal.element.HttpContextElement] - Registered http context [null] did not contain a valid http context $
2019-03-05 14:49:05.606 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.items'
2019-03-05 14:49:15.017 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.sitemap'
2019-03-05 14:49:17.129 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.things'
2019-03-05 14:49:38.429 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2019-03-05 14:49:44.423 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'home.rules' has errors, therefore ignoring it: $

2019-03-05 14:49:58.347 [WARN ] [ore.common.registry.AbstractRegistry] - Cannot add "BridgeImpl" with key "onewire:owserver:7da51992". It exi$
2019-03-05 14:50:06.644 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://192.168.1.200:8080
2019-03-05 14:50:06.664 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://192.168.1.200:8443
2019-03-05 14:50:15.189 [INFO ] [ebuilder.internal.HomeBuilderServlet] - Started Home Builder at /homebuilder
2019-03-05 14:50:17.884 [INFO ] [openhab.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2019-03-05 14:50:21.376 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2019-03-05 14:54:43.717 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'home.items'

Any help is appreciated! Thanks!

How many rules are defined in your home.rules file? There’s a syntax error in there somewhere.

From what you posted in your original post, this doesn’t look right.

}End if

Hi Mark,

I only have 1 rule in home.rules file.

I picked at it again some tonight. I have gotten it further!

Below is the latest home.rules file I have. I’ll post the log file after that. I can’t figure out why it’s busting…

rule "Solar Panel Charged And Ready / Pump On"
when
	Item SP changed
then
		var SP_Temp = (SP.state as QuanityType<Number>).intValue
		var HWT_Temp = (HWT.state as QuantityType<Number>).intValue
	if (SP_Temp > (HWT_Temp + 10)) 
		GPIO_LAMP.sendCommand(ON)
	else if (SP_Temp < 33)
		GPIO_LAMP.sendCommand(OFF)
	end

Here is the openhab.log file…

2019-03-05 22:35:52.302 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Solar Panel Charged And Ready / Pump On': Could not cast 83.075 °F to void; line 5, column 18, length 31

Cheers!

Got it fixed! It’s working.

What I’d really like to have it check is more like an OR statement. But this is working for now. :slight_smile: Now it’s time to figure the rest of my solar panel project out. Seems as though the software end seems to be working.

Thanks again!

For those looking – Here is the final code. Cheers!

rule "Solar Panel Charged And Ready / Pump On"
when
	Item SP changed
then
		var SP_Temp = (SP.state as Number)
		var HWT_Temp = (HWT.state as Number)
	if (SP_Temp > (HWT_Temp + 10)) 
		GPIO_LAMP.sendCommand(ON)
	else if (SP_Temp < HWT_Temp)
		GPIO_LAMP.sendCommand(OFF)
	else if(SP_Temp < 33)
		GPIO_LAMP.sendCommand(OFF)
	end```

It didn’t work because you spelled QuantityType wrong.

You might consider installing and using VS Code with the openHAB extension. It will make it very easy to spot these types of errors.