SEPIA-Framework / sepia-docs

Documentation and Wiki for SEPIA. Please post your questions and bug-reports here in the issues section! Thank you :-)
https://sepia-framework.github.io/
237 stars 16 forks source link

openHAB Item recognition unclear #10

Closed MtotheKay closed 5 years ago

MtotheKay commented 5 years ago

Hello,

since I now got the connection to openHAB running. I tried to "turn the lights on" With the log level on debug on openHAB side, I can see that S.E.P.I.A. indeed tries to set a value for an Item. But the Item is not a switch or a dimmer, but most of all not a light...

Setting the "Lights" value for the "Type" in the devices list does not seem to be persistent, since the value for the previously set item is empty when I reload the page and get the device. Also none of the "light" items gets set.

So my question is: How can I see and control which Items will be affected for which action?

Thanks Martijn

fquirin commented 5 years ago

The basic idea is that the service uses the openHAB REST API to get all devices and then checks the "tags" field for SEPIA specific info (e.g. "sepia-type=...") that was assigned via SEPIA Control-HUB. If the "tags" field is empty it checks the "category" field (e.g. for "light" or "lamp") to auto-assign the "Type".

After that you should be able to say "turn on the lights" and ALL lights turn on. If you add a room via the Control-HUB you can say "turn on the light in the living-room" for example.

Setting the "Lights" value for the "Type" in the devices list does not seem to be persistent

This is strange :-/ When you change the "Type" you should see a pop-up with the message "Result: success" and then it should be stored permanently. Do you see this message?

Could you check the "tags" and "category" fields via the openHAB interface? Then we could test if info is actually available and if SEPIA managed to write the "tags" field.

MtotheKay commented 5 years ago

I created new Items for testing purposes:

Group light_group   "Lamps"         <light>
Switch sAZ_StLmp_IO "Stehlampe An/Aus"  <light> (light_group)   [ "Lighting" ]
Switch sAZ_StLmp_IO2    "Stehlampe 2 An/Aus"    <light> (light_group)   [ "sepia-type=Lighting" ]
Dimmer lamp     "lamp"          <light> (light_group)   [ "Lighting" , "sepia-type=Lighting" ]

REST Responses:

{
  "link": "http://openhabserver:8080/rest/items/sAZ_StLmp_IO",
  "state": "NULL",
  "editable": false,
  "type": "Switch",
  "name": "sAZ_StLmp_IO",
  "label": "Stehlampe An/Aus",
  "category": "light",
  "tags": [
    "Lighting"
  ],
  "groupNames": [
    "light_group"
  ]
}
{
  "link": "http://openhabserver:8080/rest/items/sAZ_StLmp_IO2",
  "state": "NULL",
  "editable": false,
  "type": "Switch",
  "name": "sAZ_StLmp_IO2",
  "label": "Stehlampe 2 An/Aus",
  "category": "light",
  "tags": [
    "sepia-type=Lighting"
  ],
  "groupNames": [
    "light_group"
  ]
}
{
  "link": "http://openhabserver:8080/rest/items/lamp",
  "state": "NULL",
  "editable": false,
  "type": "Dimmer",
  "name": "lamp",
  "label": "lamp",
  "category": "light",
  "tags": [
    "Lighting",
    "sepia-type=Lighting"
  ],
  "groupNames": [
    "light_group"
  ]
}

None of these items get activated. Instead it seems like the first returned Item with the category (Icon) "light" will be activated with the command "lights on".

Is there a way to see the stored values in the database?

Regarding your question: I created another Item via PaperUI and tried to set the type and the room with the SEPIA control HUB. This is the REST result for that Item after I tried to set the values:

{
  "link": "http://openhabserver:8080/rest/items/TestLamp",
  "state": "NULL",
  "editable": true,
  "type": "Dimmer",
  "name": "TestLamp",
  "label": "Test Lamp",
  "category": "Light",
  "tags": []
  "groupNames": [
    "light_group"
  ]
}

I get the "Succsess" response, but the Tags in openHAB stay empty. There is no REST call to be found in the Logs.

Is there a way to see what is actually stored in the Database?

fquirin commented 5 years ago

Is there a way to see what is actually stored in the Database?

The SEPIA server reads the data directly from openHAB REST API and the Control-HUB writes them directly to the "tags" field on the openHAB server so in that sense there is no additional SEPIA database entry required. Or did you mean some other data?

"sAZ_StLmp_IO2" and "lamp" show the required entries in "tags". Did you set them via the Control-HUB as well? I'll quickly check the openHAB interface (in SEPIA) again to check what happens when no room is given (it might trigger the first lamp found), in the meantime could you add a different room to each of the lamps (the same way you've managed to add 'sepia-type= Lighting') and then try to trigger them e.g. via "lamp in living-room" and "lamp in bedroom"?

I get the "Succsess" response, but the Tags in openHAB stay empty. There is no REST call to be found in the Logs.

This one really confuses me. Could it be that the browser cache is showing old data? The Control-HUB writes the data directly to the openHAB REST endpoint as far as I remember (I'll check this again as well).

Since you managed to trigger a (random) lamp somehow and the "tags" field was modified at some point I assume all server connections should work fine.

MtotheKay commented 5 years ago

I see. So the Data has to be stored in openHAB itself. That may be a part of the problem, since I'm using the .items file for most of my items. Items defined in files can't be changed over the interface (Neighter Paper UI nor REST API).

I was hoping to see which entries SEPIA found in the Device List of the Control Hub, since it only shows: "- Choose -" (Even for sAZ_StLmp_IO2).

I did add a room for sAZ_StLmp_IO2 like this: Switch sAZ_StLmp_IO2 "Stehlampe 2 An/Aus" <light> (light_group) [ "sepia-type=Lighting", "sepia-room=Living room" ]

So the REST Response looks like this:

{
  "link": "http://openhabserver:8080/rest/items/sAZ_StLmp_IO2",
  "state": "NULL",
  "editable": false,
  "type": "Switch",
  "name": "sAZ_StLmp_IO2",
  "label": "Stehlampe 2 An/Aus",
  "category": "light",
  "tags": [
    "sepia-room=Living room",
    "sepia-type=Lighting"
  ],
  "groupNames": [
    "light_group"
  ]
}

Since sAZ_StLmp_IO2 can't be changed, I tried to set the Tags for my TestLamp Items directly via the REST API:

curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" "http://openhabserver:8080/rest/items/TestLamp/tags/sepia-room%3DBedroom"

Which creates a log entry and sets the tag.

I repeated it for this Item with the Control HUB but nothing happens.

fquirin commented 5 years ago

So the Data has to be stored in openHAB itself. That may be a part of the problem, since I'm using the .items file for most of my items. Items defined in files can't be changed over the interface (Neighter Paper UI nor REST API).

Oh I see. Interesting, I guess I'll have to find a new way to write or store this data. Maybe a separate list in the SEPIA database that synchronizes from time to time will be required :-/

In detail what SEPIA does to set a device state is:

But since you've defined all required data for 'sAZ_StLmp_IO2' I don't see why this is still not working :-(

fquirin commented 5 years ago

I just realized something when I looked at your "tags" data again. The values are incorrect :-| . I guess you took the names given in the Control-HUB selector but the actual values for types and rooms are as follows:

sepia-type:

sepia-room:

Sorry that I missed this before :-/

Here is the REST API response for one of my Hue lights:

{
        "link": "http://raspberrypi-plus.local:8080/rest/items/HueWhiteLamp1_Brightness",
        "state": "0",
        "editable": true,
        "type": "Dimmer",
        "name": "HueWhiteLamp1_Brightness",
        "label": "Brightness",
        "category": "DimmableLight",
        "tags": [
            "sepia-room=livingroom",
            "sepia-mem-state=70",
            "sepia-type=light"
        ],
        "groupNames": []
}

editable: true might play a role as well I guess, but I think that was my default setting.

MtotheKay commented 5 years ago

That's where the Rabbit is buried in the pepper ;)

Everything works now. Thank you very much 👍

I would update the wiki, but I can't :(

In the official SEPIA-Home installation this is: ~/SEPIA/sepia-assist-server/Xtensions/assist.custom.properties. Look for an entry called openhab_host and enter your openHAB server, e.g.: openhab_host=http://192.168.0.10:8080

could be:

In the official SEPIA-Home installation this is: ~/SEPIA/sepia-assist-server/Xtensions/assist.custom.properties. Look for the entrys: smarthome_hub_host and smarthome_hub_name and fill in the openHAB sever host including the port and the smarthome hub brand. (The smarthome_hub_name for openHAB is "openhab" and is case sensitive) e.g.: smarthome_hub_host=http://192.168.0.10:8080 smarthome_hub_name=openhab

and:

If you want to assign your smart devices some extra info like the location (room) go to the 'Smart Home' page inside the admin web-tools and enter the address of your openHAB server in the 'Server' field. Press 'get devices' and modify the entries as required.

could be:

Depending on the way you manage your items select the way to go forward:

If you create your Items via Paper UI Make sure the category "light" is selected. S.E.P.I.A. should recognize all Items of category "light".

If you want to assign your smart devices some extra info like the location (room) go to the 'Smart Home' page inside the admin web-tools and enter the address of your openHAB server in the 'Server' field. Press 'get devices' and modify the entries as required. S.E.P.I.A. will try to add some S.E.P.I.A. specific tags to your openHAB items. You can check if it worked by inserting: http://<openHAB Server Address>:8080/rest/items/<item name> in your browser address field. Check if the tags list sepia-type or sepia-room.

If you create your Items via .items File It seems that Items directly assigned to a channel do not accept tags. So either create a second item for each lamp and write a rule to set the value or create a group to control the lights. Since you don't want to control each lamp individually, it is good practice to create groups per room.

If you don't know, go with the groups. Create a lamp group for each room, assign it to the light items and add the tags for S.E.P.I.A. in your .items file. E.g.:

Group gLR_Light   "Dimmable Light Living Room [%s]"   <light> ["sepia-type=light", "sepia-room=livingroom"]

Possible Values for sepia-type:

  • light
  • heater
  • device

sepia-room:

  • livingroom
  • kitchen
  • bedroom
  • bath
  • study
  • garage
  • shack

S.E.P.I.A. control HUB should show the correct values if you press 'get devices'.

fquirin commented 5 years ago

Good point, will do that :+1: and thanks for your patience ;-) Happy it works now.

[EDIT] I've updated the docs, maybe you could check the .items file part again :-)