DAY/NIGHT-object with OH2.4, Astro and KNX 2.4 does not work

Hi!

I just moved in a new house with KNX and started with OH to get a DAY/NIGHT object for the KNX system, but I don’t get the “DAY/NIGHT-object” to work…

The different versions of Openhab really confuse me!

I tried it in paper ui first, but don’t get how to make rules here. The Astro binding seems to work though
Astro%20data

KNX connection works as well as I am able to switch channels of the KNX-actuators on and off with OH

I switched to Visual Studio code.

Astro.items

Number      SunElevation        "Sonnenhöhe [%.1f °]"                               <sun>       (Astro) { channel="astro:sun:kork:position#elevation" }
Switch es_ist_TAG  "TAG [%s]"
Switch es_ist_NACHT "NACHT [%s]"
Switch es_ist_DAEMMRIG "DÄMMERUNG [%s]"
Switch KNX_TAG_NACHT_DG "Tag=1 Nacht=0 Umschaltung" {knx="4/4/0+"}

rules\Tag_Nacht_Dämmerung.rules

rule "Astro Regeln Tag Nacht Umschaltung"
when
Item SunElevation changed or System started
then
if (SunElevation.state < -6) {
sendCommand(KNX_TAG_NACHT_DG, ON)
if (es_ist_TAG.state==ON || es_ist_TAG.state==NULL) {
logInfo("Astro Regeln", "Sonnenstand < -6 Grad - Nacht")
sendCommand(es_ist_DAEMMRIG, OFF)
sendCommand(es_ist_TAG, OFF)
sendCommand(es_ist_NACHT, ON)
}
}
if (SunElevation.state >= -6 &&  SunElevation.state <= 0) {
sendCommand(KNX_TAG_NACHT_DG, ON)
if (es_ist_TAG.state==ON || es_ist_TAG.state==NULL) {
logInfo("Astro Regeln", "-6 Grad <= Sonnenstand <= 0 Grad - Dämmerung")
sendCommand(es_ist_DAEMMRIG, ON)
sendCommand(es_ist_TAG, OFF)
sendCommand(es_ist_NACHT, ON)

}
}
if (SunElevation.state > 0) {
sendCommand(KNX_TAG_NACHT_DG, OFF)
if (es_ist_TAG.state==OFF || es_ist_TAG.state==NULL) {
logInfo("Astro Regeln", "Sonnenstand > 0 Grad - Tag")
sendCommand(es_ist_DAEMMRIG, OFF)
sendCommand(es_ist_TAG, ON)
sendCommand(es_ist_NACHT, OFF)
}
}
end

In ETS5 for KNX I added the GA 4.4.0 “Tag/Nacht”, but the status does not change there.

Does anyone has an idea how to solve my problem?

Thanks a lot,

Jan

This is a KNX 1.x configuration.
Please read KNX2 docu and adjust your things/items accordingly

Okay, thanks for the hint! Do I have to make things with code as well, when I have done them with paper ui already to use the rules?

Also when checking if a state is NULL you need to use === not ==.

Example:

if (es_ist_TAG.state==ON || es_ist_TAG.state === NULL) {

Do you have error messages, related to the rule, in the logs? If so please post the log.

You need to configure your bridge-thing for accessing the KNX-bus (what you did already, since you said you can issue commands).

For your Day/Night-object you likely want to configure a separate generic KNX-thing (without a physical address) with at least one channel (Type switch-control) and assign your “ga=4/4/0” to this channel.

If want to stick with the PaperUI for this instead of using configuration files, this is fine of course. But check the examples in the bindings documentation to unterstand the dependencies :wink:

Again: Start reading the KNX2 binding documentation (again). Since you are familiar with the KNX itself, a lot of things will getting clearer then :wink:

Incorrect, I am afraid.

You need to use == NULL as NULL is a state value recognized ny openHAB
You need to use === null as null is a java reserved word indicating an uninitialized variable.

1 Like

I should have known better,:roll_eyes: knee jerk responses can be quite embarrassing. @vzorglub Thanks for setting it straight.:+1:

Look what I found in my notes:laughing:

NULL - indicates an Item is not yet initialized
null - part of the language, indicates that a variable does not have a value

Hi! I have started reading the documentation and changing the code, but it is still not working.

Does anyone maybe has succesfully configured a day/night object with OH2.4 and KNX2.x and can provide me the code :heart_eyes:?

KNX.things

Bridge knx:ip:MDT_IPG "MDT IP Gateway" @ "KNX" [ 
    ipAddress="192.168.178.21", 
    portNumber=3671, 
    localIp="192.168.178.37", 
    type="TUNNEL", 
    readingPause=50, 
    responseTimeout=10, 
    readRetriesLimit=3, 
    autoReconnectPeriod=1,
    localSourceAddr="1.1.31" ] 

{
    Thing device MDTSchaltaktor12fach @ "KNX"  [
        address="1.1.4",
        fetch=true,
        pingInterval=600,
        readInterval=3600
    ] {
        Type switch        : Aussenlicht_Strasse        "Channel 1.1"       [ ga="0/0/26+<0/2/25" ]
        Type switch        : Licht_Kueche               "Channel 1.2"       [ ga="0/0/1+<0/2/0"  ]
    }

    Thing device MDTSchaltaktor20fach_Light @ "KNX"  [
        address="1.1.1",
        fetch=true,
        pingInterval=600,
        readInterval=3600
    ] {
        Type switch        : A        "Channel 2.1"       [ ga="0/0/9+<0/2/8" ]
        Type switch        : B        "Channel 2.2"       [ ga="0/0/16+<0/2/15"  ]
        Type switch        : C       "Channel 2.2"       [ ga="1/0/5+<1/1/5"  ]
        Type switch        : D       "Channel 2.2"       [ ga="0/0/17+<0/2/16"  ]
    }
   
   Thing  Switch.control : KNX_TAG_NACHT_DG "Tag=1 Nacht=0 Umschaltung" {knx="4/4/0+"}
}

Rules

rule "Aussenbeleuchtung-EIN"
when
Channel 'astro:sun:local:set#end' triggered START
then
sendCommand(knx:device:453d2c65:Aussenlicht_Strasse, ON)
end
rule "Aussenlicht Strasse aus"
when
Channel 'astro:sun:local:rise#start' triggered START
then
sendCommand(knx:device:453d2c65:Aussenlicht_Strasse, OFF)
end

Thanks a lot,

John

I think there is a mistake in the control thing definition.
From the binding docs this should be

 Type switch-control

not

Type  Switch.control

I guess the

4/4/0+

should get the ‘+’ removed as there is no listening group address following the ‘+’

Thanks, I changed both and get the following error in the log file now:

2019-01-07 19:52:04.822 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Aussenlicht Strasse ein.rules' has errors, therefore ignoring it: [5,16]: mismatched input ':' expecting ')'

[5,23]: mismatched input ':' expecting 'end'

2019-01-07 19:52:10.636 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'KNX.sitemap' has errors, therefore ignoring it: [3,6]: required (...)+ loop did not match anything at input 'item='

[7,3]: extraneous input '}' expecting EOF

What does that mean?

Guess you have some syntax errors.
Define an item, then use item.sendCommand(…).
I doubt this will work on the channel itself.
As for the other error:Check at the line and character mentioned, this may lead you to the mismatched bracket.

Do you use VS code?

Yes, I use VS Code.

I added “item.” at both rules;

rule "Aussenlicht Strasse EIN"
when
Channel 'astro:sun:local:set#end' triggered START
then
item.sendCommand(knx:device:MDT_IPG:Aussenlicht_Strasse, ON)
end

The reason for the second error may be the missing item “KNX_TAG_NACHT_DG” in “KNX.items”

What really confuses me is how to connect the day/night object with KNX. For real components like an actuator this is clear to me and this is working fine. But the day/night object is artificial…

Sorry, I get the impression you are not really familiar with the concept of things, items, channels and how they interact with each other.
Here a very (!) rough overview:
Basically you start with a thing (a representation of a physical device or a service).
Things have channels through which they inform about their state (e.g. temperature values) or can be triggered to do something (e.g. a switch channel of an actor).
Based on these channels you can define items (in .items files), e.g. a Switch, a Number or a Contact item.
Within the items file you say which item is related to which channel(s).
So those all are separate objects, created and linked with each other by your customizing settings.
It is clear that just writing “item” is not enough.
Items are referenced in your rules by their corresponding names.
E.g. you could define a Switch item named “MySwitch”.
Within the rule you could set the switch by using MySwitch.sendCommand (ON)

I really recommend you to read the documentation of the knx binding, it shows examples of things, channels, items and how to use them.
But first (and this is most important) go for the concepts documentation, these will help you to understand very basic things.
In addition the is documentation for beginners available that will help you sorting things out even more.

Thanks for your help and patience Oggerschummer and all others :sunglasses:. You are right: I am just starting to learn about this great tool, which is quite hard in the beginning as I am not familiar with programming…

I think I understand the basic system and also made it to control the actuator channels via OH.
What I don’t get running is to generate the day/night object and to write its value into the KNX system…
The idea is that openhab should write 1 for day and 0 for night to the KNX GA 4/4/0 based on the triggered astro binding events sunset and sunrise.

I will continue to try solving it tonight by try and error, but also appreciate your support!

Jepp, this beast can be hairy in the beginning :joy:

OK, let´s see:

In your Thing definition from above add the thing like this (drop the previous Thing with the Switch.Control, you can make it more fancy later):

Thing device KNXDayNightWrapper "DayNight"  {		
        Type switch-control : day [ ga="4/4/0" ]
    }

Then add an items-file (e.g. knx.items) and put a switch in it like:

Switch itIsDay { channel="knx:device:MDT_IPG:KNXDayNightWrapper:day" }

In your rule replace the sendCommand stuff you have with

itIsDay.sendCommand(ON)

If you own ETS you can assign GA 4/4/0 to all DayNight-Objects ( I have MDT as well, so I know there is one within the Glastaster and the Smart Taster).

You see the links ?
Properly specify the bridge to which the thing is linked to, then use the device and the channel to form a link within the item created in the items file.
This will cause the value to be sent to the bus whenever the switch is set in your rule when a sunrise triggered it.
Do not forget to implement it the same way for the sun setting, except that you send “OFF” within your sendCommand.

I hope I made no typos or logical errors (do not have access to my openhab to test it from where I am).

Overall what was missing:
Proper item definition with valid linking to the items channel on the IP bridge you defined (The documentation could be enhanced here as naming a device “generic” iand using “bridge” for the bridge s not very helpful for novice users (I made a similar mistake and was wondering why by values did not reach the bus)

Good luck,
Oggerschummer

Hi!

thanks for the walkthrough. The day/night object is set for several KNX devices and I have two switches now in paperui. First switch switches day on and off and the second switch the same for night. Thus I can switch between day and night manually now and the devices react to it.

image

This seems to work, but this morning it didn’t switch back to “day”. I had to do it maunally again.

KN things

    Thing device KNXDayNightWrapper "DayNight" 
     {		
        Type switch-control : day [ ga="4/4/0" ]
        Type switch-control : night [ ga="4/4/0" ]
    }

KNX.items

/*External: */

Switch itIsDay { channel="knx:device:MDT_IPG:KNXDayNightWrapper:day" }

Switch itIsNight { channel="knx:device:MDT_IPG:KNXDayNightWrapper:night" }

Rules
Night.rules

rule "Night"
rule "Night"
when
Channel 'astro:sun:local:set#event' triggered End
then
itIsNight.sendCommand(ON)
end

Day.rules

rule "Day"
when
Channel 'astro:sun:local:rise#event' triggered START
then
itIsDay.sendCommand(ON)
end

Is it possible to have just one switch, where “on” is “day” (1) and “off” is “night” (0)?

Hi,

that´s why I proposed only one item and one switch in my answer.
In your rules use the same item (switching one item usually does not affect others…!).
And you did not switch the second item OFF when switching the other to ON.
One channel, one item is the way to go for.

But good to hear it is finally working. Please mark this as solved.

Regards,
Thomas

rule "Night"
when
    Channel 'astro:sun:local:set#event' triggered End
then
    itIsNight.sendCommand(ON)
    itIsDay.sendCommand(OFF)
end

rule "Day"
when
    Channel 'astro:sun:local:rise#event' triggered START
then
    itIsDay.sendCommand(ON)
    itIsNight.sendCommand(OFF)
end