Contact Item name form String DLS Rules

  • Platform information:
    • Hardware:RPI3
    • OS: Openhabian 2.5.7

Hi Community,
I have some Rules Problem:
I Use Window Contacts wich have an On/Off Channel and for my Sitemaps etc I convert the On/Off to a Contact Item Open/Colosed:

Items:

Switch Buero_Fenster “Bürofenster Switch” (gVr, gVrp, gFe)
Contact Buero_Fensters “Bürofenster [MAP(de.map):%s]” (gWd0, gWd, gVrp)

Rule:

rule “Buero”
when
Item Buero_Fenster changed
then
switch Buero_Fenster.state {
case ON:{Buero_Fensters.sendCommand(OPEN)}
case OFF:{Buero_Fensters.sendCommand(CLOSED)}
}
end

I have a lot of these Contacts to install now, so I dont want to wirte a Ruel for each:

New Rule:

rule “Fenster”
when
Member of gFe changed
then
var Fenster = triggeringItem.name + “s”
switch triggeringItem.state {
case ON:{Fenster.sendCommand(“OPEN”)}
case OFF:{Fenster.sendCommand(“CLOSED”)}
}
end

I have this (var itemName = triggeringItem.name + “something”) working for On/Off items but for the Contact Item it shows the following Log:

2020-08-19 07:34:58.987 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert ‘OPEN’ to a command type which item ‘Buero_Fensters’ accepts: [RefreshType].

Maybe I have just missed something :slight_smile:
Anybody any Idea?

Tanks in advantage
Andy

Hi,
CONTACT is a type like in your phone book.

Hey Richard,

thanks for your answer, but do you know what is the rigt Type?
RestAPI says Contact:

{
“link”: “http://192.168.178.28:8080/rest/items/Buero_Fensters”,
“state”: “CLOSED”,
“transformedState”: “geschlossen”,
“stateDescription”: {
“pattern”: “MAP(de.map):%s”,
“readOnly”: false,
“options”: []
},
“editable”: false,
“type”: “Contact”,
“name”: “Buero_Fensters”,
“label”: “Bürofenster”,
“category”: “window”,
“tags”: [],
“groupNames”: [
“gWd0”,
“gWd”,
“gVrp”
]

Also the old rule is working and Docs say:

Contact Status of contacts, e.g. door/window contacts. Does not accept commands, only status updates. OpenClosed

Are these real sensors? Can we see how your Things are defined? Your Item(s) don’t seem to point to any channels?

Hey,

it is an Zigbee Switch, linked in PaperUI

{
“statusInfo”: {
“status”: “ONLINE”,
“statusDetail”: “NONE”
},
“firmwareStatus”: {
“status”: “UNKNOWN”
},
“editable”: true,
“label”: “Fenster_Buero”,
“bridgeUID”: “zigbee:coordinator_cc2531:b20fefa4”,
“configuration”: {
“zigbee_macaddress”: “00158D000446FE30”
},
“properties”: {
“zigbee_logicaltype”: “END_DEVICE”,
“zigbee_powerlevel”: “FULL”,
“zigbee_manufacturercode”: “0x1037”,
“modelId”: “lumi.sensor_magnet.aq2”,
“zigbee_networkaddress”: “2233”,
“zigbee_powersource”: “DISPOSABLE_BATTERY”,
“zigbee_stkversion”: “2”,
“zigbee_datecode”: “20161128”,
“zigbee_zclversion”: “1”,
“zigbee_routes”: “[]”,
“zigbee_lastupdate”: “”,
“zigbee_stkcompliance”: “0”,
“vendor”: “LUMI”,
“zigbee_powermode”: “RECEIVER_ON_IDLE”,
“zigbee_powersources”: “[DISPOSABLE_BATTERY]”,
“hardwareVersion”: “2”,
“zigbee_neighbors”: “[]”,
“zigbee_applicationVersion”: “3”,
“zigbee_device_initialised”: “true”,
“zigbee_devices”: “[]”
},
“UID”: “zigbee:device:b20fefa4:00158d000446fe30”,
“thingTypeUID”: “zigbee:device”,
“channels”: [
{
“linkedItems”: [
“Buero_Fenster”
],
“uid”: “zigbee:device:b20fefa4:00158d000446fe30:00158D000446FE30_1_switch”,
“id”: “00158D000446FE30_1_switch”,
“channelTypeUID”: “zigbee:switch_onoff”,
“itemType”: “Switch”,
“kind”: “STATE”,
“label”: “Switch”,
“defaultTags”: [],
“properties”: {
“zigbee_endpoint”: “1”
},
“configuration”: {
“zigbee_reporting_polling”: 900
}
}
]
}

as mentioned in post before the old rule is working, only then new on throws the error

You’re doing something different in the second rule: you’re sending "OPEN" instead of OPEN

But ultimately it seems like this would be far easier if your Thing channel was a CONTACT type in the first place. But I don’t use the Zigbee binding, so not sure what’s involved, or if it’s even possible.

Tried this already:
VSCode:

Type mismatch: cannot convert from OpenClosedType to String

Log:

Rule ‘Fenster’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null

I guess the problem is that Fenster is not actually an Item object, it’s just a string. Try using the following command syntax instead:

sendCommand(Fenster, “OPEN”)

Instead of

Fenster.sendCommand(“OPEN”)

Or use

postUpdate(Fenster, “OPEN”)

Based on this:

Tried to link the Contact direc to the Thing using Map:

window.map:

OFF=CLOSED
ON=OPEN

PaperUI:

But nothing happened now on the Item Buero_Fensters
Maybe someone knows the issue here, cause this seems like the best way to solve this :slight_smile:

But anyway, the postUpdate did the trick, thanks a lot…,
sometimes the hints are everywhere but i cannot see them :slight_smile:

Greetings Andy

You really need to start looking in your openhab.log, it tells you a lot about problems it encounters with rules and can help you fix it.

I think you are saying -
You’ve got a Switch type Item, because that what the binding gives you.
That has an ON/OFF state, of course.
You would like to see that represented in your sitemap instead with text like “Open” or “Closed”, or maybe “Offnen” and “Zu”, right?

You don’t need a Contact Item for that, just a “translation” for the sitemap.

You will need to install the MAP transformation service add-on.

You will need to create a MAP file using a text editor, and place it in the correct /transform folder.

doorsw.map

OFF=zu
ON=offen
-=undefiniert

Now, tell your Item to use that map in its label [state presentation]

Switch Buero_Fenster "Bürofenster [MAP(doorsw.map):%s]" (gVr, gVrp, gFe)

Then just place the Item on your sitemap

Text item=Buero_Fenster

The Item wil keep the ON/OFF state internally e.g. in rules use, but will display the text zu/offnen.
You can share one MAP file with many Items.

Try this in your sitemap

Text item=Buero_Fenster valuecolor=[ON="red"]

Hi Rossko,

thanks for the support.
The log has no entries in this case only the on/off state which changes.
I already have Map Transformation working for my Sitemaps but I need the contact Item for the Window and Door icon to change dynamicly according to the state (showed as open or closed).
When I use the Window icon whith a switch item and Map transformaiton, in my sitemap the Icon is only static an with the contact it is dynamic, the value is showed correct (as in my map file).

What I tried to do was linking the Contact Item to an Switch Channel via Paper UI by selecting the Map Transformation.

Greetings Andy

No you don’t.
Make a set of custom dynamic icons, you can copy these from the standard images.
mydoor.svg
mydoor-on.svg
mydoor-off.svg
etc.