Multiple Actions with on Button

S in switch wars the Problem :wink:

When i trigger the Switch in get in

events.log

2017-11-18 12:20:16.833 [ItemCommandEvent ] - Item ‘goodnight’ received command ON
2017-11-18 12:20:16.846 [ItemStateChangedEvent ] - goodnight changed from NULL to ON

openhab.log

2017-11-18 12:18:48.010 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘goodnight.sitemap’

the Rules File is in

/etc/openhab2/rules

Ok - sorry for the typo! :wink:
please try multiple times - your rule should fire the next round.

you could also change the rule

rule "good night"
when
	Item goodnight changed to ON
then
	// log the item change to openhab.log
	logInfo("Good Night", "Good Night switched changed to" + goodnight.state)
	goodnight.sendCommand(OFF)
end

now it should fire everytime.
Explanation: at first run of either OH2 (re)starting or item reloading (everytime an .items file is changed, the whole items get initialized again by design) the state of “goodnight” is not OFF, but NULL (or UNDEF).

Now if your rule file is loaded and working, after triggering “goodnight” switch there should be a line saying something like

blaablaablaa [INFO] Good Night switched changed to ON

and the switch should change straight back to OFF

Are you seeing anything like this?

Thx so much for your Help guys :slight_smile:

So now it works (after the second “switch” :wink: )

event.log

2017-11-18 12:34:40.453 [ItemCommandEvent ] - Item ‘goodnight’ received command OFF
2017-11-18 12:34:40.467 [ItemStateChangedEvent ] - goodnight changed from ON to OFF
2017-11-18 12:34:41.686 [ItemCommandEvent ] - Item ‘goodnight’ received command ON
2017-11-18 12:34:41.712 [ItemStateChangedEvent ] - goodnight changed from OFF to ON
2017-11-18 12:34:42.145 [ItemCommandEvent ] - Item ‘goodnight’ received command OFF
2017-11-18 12:34:42.160 [ItemStateChangedEvent ] - goodnight changed from ON to OFF
2017-11-18 12:34:43.306 [ItemCommandEvent ] - Item ‘goodnight’ received command ON
2017-11-18 12:34:43.319 [ItemStateChangedEvent ] - goodnight changed from OFF to ON
2017-11-18 12:34:43.356 [ItemCommandEvent ] - Item ‘goodnight’ received command OFF
2017-11-18 12:34:43.368 [ItemStateChangedEvent ] - goodnight changed from ON to OFF

So now i need the syntax for the Thermostate and later for my lights :slight_smile:

PS: I think you have a bit of a potential bug in here.

  • StubeThermostatCurrentTemp = the actual Temperature returned from the thermometer within your device.
  • StubeThermostatTargetTemperature = the set Temperature, your Thermostat is set to reach

if for some reason, the room is heated (e.g. cooking in the kitchen or sun in the living room) and the current temperature is above 17°C, your rule won’t change the set temperature. So judging from your use case, I would either compare the set temperature (if your device and the binding are capable of showing it), or nevertheless change the set temperature to 17, regardless of the actual room temperature?

Yeah, I don’t want to be dependentcies in this case.

The thermostats should be set to 17 degrees Celsius and all lamps should be switched off and the lamp in the bedroom turned on.

glad, it worked out now!
the syntax for your thermostat should work as you configured this in PaperUI (see screenshot). The lights (if they’re Hue lights) work the same way and you can adress your lights in rules as we did just with your set temperature.
Your linked item in PaperUI is exactly the item syntax you can use in rules. If you want your lights off in the goodnight rule, just use “sendcommand” with OFF as you did with the goodnight state.
so, if you like, the rule could read:

rule "good night"
when
	Item goodnight changed to ON
then
	// log the item change to openhab.log
	logInfo("Good Night", "Good Night switched changed to" + goodnight.state)

	// turning lights off
	StubeHuelight.sendCommand(OFF)
	KuecheHuelight.sendCommand(OFF)

	// bathroom light on
	BadHuelight.sendCommand(ON)

	// heating set temp to 17
	StubeThermostatTargetTemperature.sendCommand(17)
	BadThermostatTargetTemperature.sendCommand(17)
	KuecheThermostatTargetTemperature.sendCommand(17)

	// sending goodnight to OFF again
	goodnight.sendCommand(OFF)
end

So, this is of course, if you link your Hue lights items in the three rooms to the respective names.

Just one more thing: What do you want to do with the “goodnight” item afterwards? right now the state will immediately Change to OFF again after the rule is finished. If you’d like to have some logic later on, I recommend having a “goodnight” item with OFF until either you set it to ON again (e.g. also via alexa) in the morning or you have a Little cron-based rule, which turns goodnight on at 6am or whatever time you like.

Now it works fine thx again for all your help.

This command is simple my “go to bed setup”.
In the Morning i have a Alexa Routine “she” switch the Light on in Bedroom and read the news, the Heating have an Automatic program.

Maybe i have more Ideas in the future.

At next i wanne buy some sockets for my tv, add my Kodi and but i think thats not possible i wanne start my Andorid tv and start the kodi app.

If you have Sony android tv like i do then i suggest to take a look in here: Sony Devices Binding

I think it’s not good to switch your tv on and off by controlling power outlets. With newer tvs there’s a possibility to control them through http binding or maybe exec binding using scripts. You can find lots of information on this forum. Search is your friend :wink:

I have a Philips Android TV and it seems ther ist no “easy way” to controll it.