How can a rule trigger a switch on sitemap!?

Hi there,

it’s everytime the same, a lot of hits on search, but all different to my issue!

I’m using KNX Binding for my heating system. A switch on the sitemap starts the heating for about 60 min. After that the heating rule turns the knx-actor off (runs well) but the switch on the sitemap is still “ON”

Sounds like a piece of cake, but i’m still without the right idea!

someone a well idea?!

Thx in advance!
Bernd

In a rule issue a postUpdate to the switch and it will change it without the command being forwarded to device.

Unfortunately this doesn’t work!

rule

rule "manuelle Wonzimmer-Heizung"
when
	Item Wohnzimmer_Heizung received command
then
	if (Wohnzimmer_Heizung.state == ON)
	{
	Heizung_Wohnzimmer_Stellgroesse.sendCommand(100)
	logInfo("Heizung", "WEB: Wohnzimmer = 100% für 60 min")
	

		timerWohnzimmer = createTimer(now.plusMinutes(2))
		[|	
		Heizung_Wohnzimmer_Stellgroesse.sendCommand(0)
		logInfo("Heizung", "WEB: Wohnzimmer Auto = 0%")
		Heizung_Wohnzimmer.postUpdate(OFF)
		]	
	}

sitemap

			Frame label="Heizungs-Schaltung 60 min."
			{
			Switch item=Duschbad_Heizung
			Switch item=Wohnzimmer_Heizung
			}

items

// Heizung virt. Schalter
Switch 		Duschbad_Heizung			"Duschbad Heizung"			<heating>	
Switch 		Wohnzimmer_Heizung			"Wohnzimmer Heizung"			<heating>					

Dimmer Heizung_Duschbad_Stellgroesse 	"Heizung Duschbad Stellwert [%d %%]"		<heating> 		{knx="<5.001:3/1/8"}
Dimmer Heizung_Wohnzimmer_Stellgroesse 	"Heizung Wohnzimmer Stellwert [%d %%]"		<heating> 		{knx="<5.001:3/1/1"}

log

2016-10-30 08:14:19.092 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'Heizung.rules'
2016-10-30 08:14:51.346 [INFO ] [g.openhab.model.script.Heizung] - WEB: Wohnzimmer = 100% für 60 min
2016-10-30 08:14:51.737 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'manuelle Wonzimmer-Heizung': org.eclipse.xtext.util.PolymorphicDispatcher$NoSuchMethodException: Couldn't find method ''_assignValue'' for objects [JvmVoid:  (eProxyURI: Heizung.rules#xtextLink_::0.2.7.2.0.0.1.0.3::0::/1), <null> timerWohnzimmer <XFeatureCallImplCustom>, org.openhab.model.script.internal.actions.TimerImpl@1f7d2df, org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext@fb645f, org.eclipse.xtext.util.CancelIndicator$1@5a163]
2016-10-30 08:16:51.817 [INFO ] [g.openhab.model.script.Heizung] - WEB: Wohnzimmer Auto = 0%

Could this help to find the problem?

Would trying the format postUpdate(item, value) make any difference? I know there is a little difference in how the snippet is interpreted, but to be honest don’t really understand the nuances…:confused:

Did you declare the timer variable as a global? The error appears to be complaining that timerWohnzimmer doesn’t exist.

I’ll try!
…but could you please give the whole example who to use the .postUpdate command???

Thx in advance!

Okay,

that sounds good! Actually I did not declare the variable!
Know the question, is it necessary to declare it as global or is local fine?
Where is the right place for a variable to be defined as local or global??

thx

The rule as written/posted you can do either. In fact, you could just drop it entirely:

createTimer(now.plus ...

You never refer to it again. However, if there is an else you haven’t posted above which cancels the timer if the state is OFF, then you need to declare it as a global. All rule local variables go away once the rule finishes exiting which means timerWohnzimmer will cease to exist.

To declare a variable as local just put the val or var line between the then and end of the rule. But be aware you must declare it before you can use it so in this case it would have to go above the timerWohnzimmer = line.

To declare a variable as global the val and var need to be above the first rule in the file.

when
	Item Wohnzimmer_Heizung received command
then
	if (Wohnzimmer_Heizung.state == ON)

This fragment is concerning, because you might be trying to see what the command was that triggered the rule. You would use receivedCommand instead of Wohnzimmer_Heizung.state to find this out.

Heizung_Wohnzimmer.postUpdate(OFF)

If the intention is to turn off the heater, then sendCommand(OFF) is what you should do instead of merely updating the state of the switch item. The rule only does anything if it was sent the ON command, so you won’t create an endless loop.

In other words, you only need to react to receiving switch commands, and the switch state is actually not needed in the rule at all.

The complete rule below should work:

rule "manuelle Wonzimmer-Heizung"
when
	Item Wohnzimmer_Heizung received command
then
	if (receivedCommand == ON) {
		Heizung_Wohnzimmer_Stellgroesse.sendCommand(100)
		logInfo("Heizung", "WEB: Wohnzimmer = 100% für 2 min")
		createTimer(now.plusMinutes(2)) [| Heizung_Wohnzimmer.sendCommand(OFF) ]
	} else if (receivedCommand == OFF) {
		Heizung_Wohnzimmer_Stellgroesse.sendCommand(0)
		logInfo("Heizung", "WEB: Wohnzimmer Auto = 0%")
	}
end

Hi,

okay, I tried your changes…
the rule works as fine as before… the heating stopped before as well, but as before, the website item (switch) doesn’t change the state back to off!

Sorry!

Hmmm… Is it that the UI is wrong, or that the switch item’s state is really not OFF after sending the OFF command from the timer? You can check with the REST API:

http://youropenhabnameoraddress:8080/rest/items/Wohnzimmer_Heizung/state

If the UI representation of the switch does not agree with the state returned via the REST API, then it’s probably a bug in the UI.

Wow! Okay, that’s very interesting now!

Because, my rdd4j chart shows me the heating is OFF and the knx heating actor (hardware) is in fact OFF!!!
In other word, the reality is that the heating is OFF, the rdd4j-chart shows the same, the LOG shows a successful turn OFF, but the REST API is thinking about ON???

Isn’t that wierd??

So, in order to be clear, the timer did run, it did send the OFF command to the switch, but both the UI and the REST API thereafter both show that the switch’s state is still ON? Unless something is preventing the autoupdate logic from changing the state of the switch to match the command, it seems like a weird bug.

Could you try the latest KNX 1.9.0-SNAPSHOT binding, where there was a recent change to how it deals with autoupdate logic as well as solving a problem reflecting changes back to the KNX bus, just to see if it behaves the same? It ought not be related, but it could be…

hmm,

I really don’t want to annoy you, but I never deployed a “snapshot”. I’ve no idea what to do?

I’m running OpenHab 1 on a rasbian light (Raspbian-Jessie) and deployed all through “apt-get”.

sudo apt-get install openhab-addon-binding-knx 

Therefore, I’ve never deployed a package from local file… What do I have to do???

You would move the existing org.openhab.binding.knx-1.8.3.jar file out of your /usr/share/openhab/addons directory, and download the linked .jar file to your /usr/share/openhab/addons directory. For example:

cd /usr/share/openhab/addons
sudo mv org.openhab.binding.knx-1.8.3.jar /tmp
wget https://openhab.ci.cloudbees.com/job/openHAB1-Addons/lastSuccessfulBuild/artifact/bundles/binding/org.openhab.binding.knx/target/org.openhab.binding.knx-1.9.0-SNAPSHOT.jar

Thanks for the advice, it looks like the snapshot was deployed successfully.

But the issue is still the same!

By the way, when I switch on/off the lights, the UI of openHab shows the right state!!!
So far I recognized it is just a problem the the heating-switch!

Could there be an error in the knx parameters of the group addresses??

I just tried the following rule on openHAB 1.8.3 (no KNX binding in this install) and it worked exactly as hoped.

rule MyTestRule
when
	Item MyTestSwitch received command
then
	if (receivedCommand == ON) {
		logInfo("Test", "switch item turned on; turn it off in 2 minutes")
		createTimer(now.plusMinutes(2)) [| MyTestSwitch.sendCommand(OFF) ]
	} else if (receivedCommand == OFF) {
		logInfo("Test", "switch item turned off")
	}
end

The UI and switch state changed to OFF when expected, and the log entries were appended:

2016-11-01 12:17:32.851 [INFO ] [org.openhab.model.script.Test ] - switch item turned on; turn it off in 2 minutes
2016-11-01 12:19:32.930 [INFO ] [org.openhab.model.script.Test ] - switch item turned off

I would be very interested to learn if the difference between success and failure was in any way related to the KNX binding. (Uninstall the KNX binding bundle and try again.)

Okay,

now I’m frustrated…

I cut the KNX-config in openhab.config and still the same behavior as before.

But than, I tried your code… it works!
Where is the difference???

Is your rule missing the end keyword as you provided it here?

I’m investigating right now…

I’m editing your code step by step to add the key knx-feature!

I’ll come back in a few minutes!
by the way the “End” was not missing!

Edit: right now it is running well!!! KNX-is doing the right thing, heating turns ON and OFF and UI showing the right state!
I’ll check now further… differences