Multiple Actions with on Button

Hello,

I’m still new to openhab and I want to perform several actions with one button.
I got my Max! Heater system and my Hue installed, after an instruction I managed to integrate Amazon Alexa.

Now I would like to have a switch with the following functions:
all heaters on 17 degrees and 2 lights off and 1 light on, I would like to connect this with Alexa to switch it on.

Is that even possible and if so, how do I do it best as a beginner?

You could define a switch item that is bound to the button. Then create a rule that is triggered on that switch. IIn the rule You can do whatever needs to be done.

Some inspiration:
http://docs.openhab.org/configuration/rules-dsl.html
http://docs.openhab.org/tutorials/beginner/rules.html

Button = Item in Openhab ?

You can work with rules … or if you only want turn on 2 Bulbs with one Switch you can link the item to both bulbs.

I do it with Ikea Tradfri so … 3 GU10 Bulbs with 1 OH2 Item …

Edit: I read your Posting now completely … you need a rule :wink:

rule "Actions with One Switch"
when
  Item SWITCH_FOR_ACTIONS changed from OFF to ON
then
    if (heater.state != 17) heater.sendCommand(17)
    if (firstBulb.state != ON) firstBulb.sendCommand(ON)
    if (secondBulb.state != OFF) secondBulb.sendCommand(OFF)
    SWITCH_FOR_ACTIONS.sendCommand(OFF)
end

Thx für your help.

Sorry again for my noob questions, am really new to this stuff.
I added in my home.items a switch

$
Switch goodnight "Good Night" [ "Switchable" ]

so in your sample

rule "good night"
when
  Item goodnight changed from OFF to ON
then
    if (heater.state != 17) heater.sendCommand(17)
    if (firstBulb.state != ON) firstBulb.sendCommand(ON)
    if (secondBulb.state != OFF) secondBulb.sendCommand(OFF)
    goodnight.sendCommand(OFF)
end

So what is the syntax with the “elements”?
I have in paper ui the my Max system for example this is the temperatur for the living room : max:thermostat:KMD1055827:KMD3066852:set_temp

is this right?

if (max:thermostat:KMD1055827:KMD3066852:set_temp != 17) max:thermostat:KMD1055827:KMD3066852:set_temp(17)

and for the Bulbs (Philips Hue) i have no on/off thing only hue:0210:001788606091:3:color
so i have set the Brightness to 0 ?

At a first glance it seems correct. It might be helpfull to do it one step at a time, and/or add log statements while creating your rule.

So i tested this

in home.items

Switch goodnight "Good Night" [ "Switchable" ]

filename is: goodnight.rules
path: /etc/openhab2/rules

rule "good night"
when
  Item goodnight changed from OFF to ON
then
	if (max:thermostat:KMD1055827:KMD3066852:set_temp != 17) max:thermostat:KMD1055827:KMD3066852:set_temp(17)
	if (max:thermostat:KMD1055827:KMD3069582:set_temp != 17) max:thermostat:KMD1055827:KMD3069582:set_temp(17)
	if (max:thermostat:KMD1055827:LEQ1149210:set_temp != 17) max:thermostat:KMD1055827:LEQ1149210:set_temp(17)
    goodnight.sendCommand(OFF)
end

I found this Switch in my Amazon Alexa but when i set this to on nothing changes.
Is there a way to add this Switch in Paper UI?

Here are some errors from openhab.log

2017-11-17 16:32:39.132 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘goodnight.rules’ has errors, therefore ignoring it: [5,9]: mismatched input ‘:’ expecting ‘)’
[5,20]: mismatched input ‘:’ expecting ‘end’

2017-11-17 16:32:39.248 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘goodnight.rules’ has errors, therefore ignoring it: [5,9]: mismatched input ‘:’ expecting ‘)’
[5,20]: mismatched input ‘:’ expecting ‘end’

2017-11-17 16:33:13.329 [WARN ] [thome.io.rest.core.item.ItemResource] - Cannot update existing item ‘goodnight’, because is not managed.

There needs to be { } after the if statement.
if (max:thermostat:KMD1055827:KMD3066852:set_temp != 17) {max:thermostat:KMD1055827:KMD3066852:set_temp(17)}

For Color bulbs:

This section differentiates between command type and state type. For ease of reading, it is possible to simply add “type” to the end of a command type thereby obtaining the state type. For example, a Color Item can receive an OnOffType, IncreaseDecreaseType, PercentType, or HSBType. Therefore the following are all valid commands one can send to a Color Item:

MyColorItem.sendCommand(ON)
MyColorItem.sendCommand(INCREASE)
MyColorItem.sendCommand(new PercentType(50))
MyColorItem.sendCommand(new HSBType(new DecimalType(123), new PercentType(45), new PercentType(67)))

I strongly encourage you to read http://docs.openhab.org/configuration/rules-dsl.html, it will get your going in you HA setup.

i change it to:

rule "good night"
when
  Item goodnight changed from OFF to ON
then
	if (max:thermostat:KMD1055827:KMD3066852:set_temp != 17) {max:thermostat:KMD1055827:KMD3066852:set_temp(17)}
	if (max:thermostat:KMD1055827:KMD3069582:set_temp != 17) {max:thermostat:KMD1055827:KMD3069582:set_temp(17)}
	if (max:thermostat:KMD1055827:LEQ1149210:set_temp != 17) {max:thermostat:KMD1055827:LEQ1149210:set_temp(17)}
    goodnight.sendCommand(OFF)
end

but i get this error again but only 1 now:

2017-11-17 17:21:01.760 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘goodnight.rules’ has errors, therefore ignoring it: [5,9]: mismatched input ‘:’ expecting ‘)’
[5,20]: mismatched input ‘:’ expecting ‘end’

What is the name of the item that is linked to the above. That doesn’t look like an item name.

Number SOMENAME

What does your item file call it?

From Here

Expand the Channel to see the linked item.

should read
if (StubeThermostatTargetTemperature.state != 17) {StubeThermostatTargetTemperature.sendCommand(17)}

Okay no error now but the temperatur dosent change.

in the events.log

2017-11-17 17:59:10.782 [ItemStateChangedEvent ] - goodnight changed from NULL to ON
2017-11-17 17:59:43.232 [ItemCommandEvent ] - Item ‘goodnight’ received command ON

The term you need to use here is “Items”.

http://docs.openhab.org/concepts/items.html
http://docs.openhab.org/configuration/items.html

No. You need to define Items that link to a Channel on a Thing. Then in your sitemap and in your Rules you use the Item.

http://docs.openhab.org/concepts/index.html

No, once you link the color channel of that Bulb to a Color Item, as documented in the links above, the Color Item will accept ON/OFF commands so you can use sendCommand(OFF).

No, PaperUI is intended to be an Administration Interface. You need to create a sitemap or habpanel and put your Items on that. These are intended to be the Uers Interfaces for your automation.

I think you would benefit from the Beginner’s Tutorial.

http://docs.openhab.org/tutorials/beginner/index.html

rule "good night"
when
  Item goodnight changed from OFF to ON
then
    if (StubeThermostatCurrentTemp != 17) StubeThermostatTargetTemperature.sendCommand(17)
    goodnight.sendCommand(OFF)
end

Take the Linked Items… than it works :slight_smile:

Hmm doesent work :frowning:

i change it to:

rule "good night"
when
  Item goodnight changed from OFF to ON
then
	if (StubeThermostatCurrentTemp != 17) StubeThermostatTargetTemperature.sendCommand(17)
	if (BadThermostatCurrentTemp != 17) BadThermostatTargetTemperature.sendCommand(17)
	if (KuecheThermostatCurrentTemp != 17) KuecheThermostatTargetTemperature.sendCommand(17)
    goodnight.sendCommand(OFF)
end

i get no error in the logs and in event.log is see
2017-11-18 09:43:24.022 [ItemCommandEvent ] - Item ‘goodnight’ received command ON

but nothing happend.

ok. so, please go some steps back and we try again from the start. :wink:

  1. You need to define an item, which is not bound to a binding, it functions just as a means to enable your good-night Actions

in your home.items it should read:

Switch goodnight "Good Night" [ 'Switchable' ]
  1. Then you need to put some rules in place, which will be run, if the switch is triggered

in your goodnight.rules it should read:

rule "good night"
when
	Item goodnight changed from OFF to ON
then
	// log the item change to openhab.log
	logInfo("Good Night", "Good Night switched changed to" + goodnight.state)
	goodnight.sendCommand(OFF)
end
  1. Put your items in a sitemap for a clear view

create or edit your goodnight.sitemap

sitemap goodnight label="Test goodnight"
{
	Frame label="Test for goodnight items" {
		Text item=StubeThermostatCurrentTemp icon="temperature"	// current-Temperature for Stube
		Setpoint item=StubeThermostatTargetTemperature minValue=5 maxValue=28 step=0.1	// set-Temperature for Stube
		Text item=BadThermostatCurrentTemp icon="temperature"	// current-Temperature for Stube
		Setpoint item=BadThermostatTargetTemperature minValue=5 maxValue=28 step=0.1	// set-Temperature for Stube
		Text item=KuecheThermostatCurrentTemp icon="temperature"	// current-Temperature for Stube
		Setpoint item=KuecheThermostatTargetTemperature minValue=5 maxValue=28 step=0.1	// set-Temperature for Stube
		switch item=goodnight label="goodnight switch"	// good-night Switch for all
	}
}

you should now have all your items for goodnight at a glance in BasicUI (come back to us, if you don’t have BasicUI or don’t know, what that is).

  1. you can now test the Switch either via Alexa or via the UI
    it should immediately change the item states in the UI and tells you so in the events.log. in openhab.log there should be the “logInfo” log entry present.

please post the events.log and openhab.log from your Tests (beginning with opening the UI and clicking on the switch).

Thx for your help, i struggle to get the sitemap working.

i created in /etc/openhab2/sitemaps a sitemap called goodnight.sitemap
and ad your code.

In Paper Ui Settings i add the Sitemap

But under Basic UI there are no Sitemaps shown

openhab.log have so errors

2017-11-18 10:29:55.061 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'goodnight.sitemap' has errors, therefore ignoring it: [10,3]: no viable alternative at input 'switch'
[12,2]: missing EOF at 'sitemap'

2017-11-18 10:29:55.130 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'goodnight.sitemap' has errors, therefore ignoring it: [10,3]: no viable alternative at input 'switch'
[12,2]: missing EOF at 'sitemap'

2017-11-18 10:42:51.348 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'goodnight.sitemap' has errors, therefore ignoring it: [1,1]: missing 'sitemap' at 'rule'
[1,6]: mismatched input '"good night"' expecting '{'

2017-11-18 10:43:25.290 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'goodnight.sitemap' has errors, therefore ignoring it: [10,3]: no viable alternative at input 'switch'

2017-11-18 10:43:25.362 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'goodnight.sitemap' has errors, therefore ignoring it: [10,3]: no viable alternative at input 'switch'

It should be be Switch item= with capital “S” in goodnight.sitemap.

And did you save your rule file in sitemaps or vice versa?

1 Like