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/
236 stars 16 forks source link

Error: One or More Attributes Could Not Be Set #174

Closed rrfranks closed 2 years ago

rrfranks commented 2 years ago

Hi! I am trying to set up Sepia with Openhab on a raspberry pi. I have had Openhab installed for a long time on my pi, but recently decided recently to install Sepia on the same pi so I could have voice control over Openhab. I successfully installed Sepia and am able to see my Openhab items in card format under the Smart Home option of Sepia . Actually I can also turn lights on & off using the power button in Sepia's Smart Home. However, when I choose a card to enter the Type or Room (through the drop down menu) I get the following error:

{ "result": "fail", "error": "One or more attributes could not be set }

Does anyone have any suggestions on what I am doing wrong? Thank you for considering my question.

fquirin commented 2 years ago

Hi,

can you check your SEPIA Assist-Server log file at SEPIA/sepia-assist-server/log.out and look for entries like this OpenHAB - 'writeDeviceAttribute' FAILED ... please? My first guess would be that OpenHAB refuses to write the data into the tags property (I think it was the tags field).

fquirin commented 2 years ago

Some additional log info submitted by @SHU-red:

2022-03-31 15:20:47 ERROR - OpenHAB - 'writeDeviceAttribute' FAILED - Device: dLedStrpBedRoom_Swt - Response: {"code":405,"error":"java.lang.NullPointerException","HTTP_REST_SUCCESS":false}

Error code 405 suggest that the openHAB server does not permit the write request. I wonder if something changed in OH3? Are there any configurable permissions for the REST API?

fquirin commented 2 years ago

The SEPIA server will try to do a HTTP PUT request like this:

curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "" "http://{openHAB_IP}:8080/rest/items/{device_id}/tags/sepia-room%3Dlivingroom"

I'm not sure anymore if this was different in OH2, maybe it has to be changed to this (which looks more like it should have been in the first place):

curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "sepia-room=livingroom" "http://{openHAB_IP}:8080/rest/items/{device_id}/tags"

I think I have to install OH3 to test it ^^

SHU-red commented 2 years ago

Sorry for the lade reply! I am absolutely willing to try out commands for you and provide the result (Although i do not know what im doing ; -) )

I just want to make some things clear regarding my setup:

  1. As already mentioned i am running OH3 and Sepia and Sepia-TTS now in docker on my home server
  2. I got the connection working thanks to your documentation via setting these variables as admin 2a. smarthome_hub_host = "http://192.myserverip:8080" 2b. smarthome_hub_name = "openhab" 2c. smarthome_hub_auth_type = "Basic" 2d. smarthome_hub_auth_data = put my "[username]:[password]" into a converter

I can see all OH3 items and their name The only thing i can not do is set a Type and Room from within Sepia

I have not configured a semantic model in OH3 (which i think was not present in OH2 ???) I do not know if Type and Room is something i also should be able to configure in OH? Or if this is only Sepia-specific?

So basically i dont know if i did something wrong, if sepia has a bug or if i did not fully configure openhab. Maybe i can proceed tomorrow searching for the root-cause and if you have any requests for me i will try to do my best to provide you the result

Thanks for your work

fquirin commented 2 years ago

Sorry for the lade reply!

actually it was pretty fast .. I thought =)

I just want to make some things clear regarding my setup: ...

looks pretty good as far as I can tell

I can see all OH3 items and their name

That is usually a good sign that the configuration is correct. I think you mentioned that the toggle buttons work as well? (on/off etc.)

I have not configured a semantic model in OH3 (which i think was not present in OH2 ???) I do not know if Type and Room is something i also should be able to configure in OH? Or if this is only Sepia-specific?

SEPIA doesn't use the semantic model in OH but its own (it was present in OH2 but might have changed a lot since then). The cards in the SEPIA Control-HUB smart-home configuration define all the necessary information. In the case of openHAB the SEPIA information is stored inside the tags field of any OH device, so you should actually be able to configure this data by hand, depending on the OH UI.

According to the most recent openHAB REST API docs a request like this should work in your case (to be called from any Linux terminal that can reach your server):

curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -u {USER_NAME}:{PASSWORD} -d "sepia-room=bedroom" "http://192.myserverip:8080/rest/items/dLedStrpBedRoom_Swt//tags"

I'm not 100% sure if this is correct, because I've tried to piece it together from my code and the OH docs. In the meantime I'll make a small update to the SEPIA OH interface and see if it still works with the old OH2, maybe it was more tolerant in v2 ^^.

fquirin commented 2 years ago

Update:

I've installed a brand new openHAB 3.2.0 instance and was able to reproduce the problem, at least to some degree ^^. Instead of the 405 error I got an 401 "authentication required" error. I then enabled basic authentication in the openHAB settings, created the base64 encoded 'user:password' string as described in the SEPIA docs and ... it worked :slightly_smiling_face:

My Hue Lamp looks like this now:

image

I just remembered another comment from the SEPIA openHAB docs:

"NOTE: If you've used "simple" mode to add your items to openHAB they might be write-protected and you will see an error when trying to edit device-cards. In this case you need to switch off simple mode, remove the item and add it again."

Not sure if this actually still plays a role, to be honest I don't even know what the "simple" mode is anymore =), but the brand new 3.2.0 worked more or less out of the box. I'll experiment more tomorrow and implement API token support as well :-)

SHU-red commented 2 years ago

Oh man you are putting so much work into this ☺️

I also have a guess: I defined all of my items via *.items file/script and not GUI. In this case the chance is high, that items can not be changed via API.

I will test

  1. Try to set type/room through sepia for a gui-generated item
  2. Try to add sepia metadata via modifying *.items file

Can you give me a hint what metadata exactly to set? What you saw there was my generic naming of my items. Can you tell me how I can set a "nice name" for using it for commands like "Ambient Light" instead of "dLedStripe_Swt"

Thanks again

rrfranks commented 2 years ago

Hi Everyone! I am sorry for taking so long to reply. Work has been very hectic this week and I am just now getting an opportunity to work on this again. Let me see if I can assimilate all the suggestions and see where that leads me. I can not thank you all enough for the effort you have put in to this...you all are GREAT!

rrfranks commented 2 years ago

Wow! All your advice really paid off. I added...

and just like magic I was able to turn off & on a lamp with my voice! Thank you all so much for giving so much time to help me out with this!!!!

SHU-red commented 2 years ago

@rrfranks Im very glad you got this working!

Porcumine sounds very interesting and could exactly be what i need! Could you maybe add some information about your setup here?

I especially have no idea how to create/use SmartHome Speakers with sepia openHAB and Google Assistant

fquirin commented 2 years ago

Porcupine sounds very interesting and could exactly be what i need!

Porcupine is also part f the SEPIA client and can be fully customized since Porcupine version v2.0 (with free access key) :slightly_smiling_face: . I'm currently implementing the v2.1 update to be in sync with their online console again.

Can you give me a hint what metadata exactly to set?

Here is a list of the SEPIA tags that you could set manually in OH. If you look at your item using the REST API URL (simply replace /settings/ with /rest/) in your browser you should see something like this:

{
    "link": "http://localhost:8080/rest/items/Huewhitelamp1_Brightness",
    "state": "0",
    "stateDescription": {
        "minimum": 0,
        "maximum": 100,
        "pattern": "%d %%",
        "readOnly": false,
        "options": []
    },
    "editable": true,
    "type": "Dimmer",
    "name": "Huewhitelamp1_Brightness",
    "label": "Brightness",
    "category": "Light",
    "tags": ["sepia-room\u003dlivingroom", "Control", "Light", "sepia-name\u003dLampe (1)", "sepia-type\u003dlight"],
    "groupNames": []
}

The tags might show up either as "sepia-room\u003dlivingroom" or "sepia-room=livingroom" that is just some encoding stuff.

I defined all of my items via *.items file/script and not GUI In this case the chance is high, that items can not be changed via API.

Ah yes. I never tried this but people mentioned that items are probably write protected in this case :grimacing: . Maybe I should explicitly mention it again in the openHAB docs section.

fquirin commented 2 years ago

Another update:

I just double-checked, if you use API token authentication you can use the Bearer auth. type and simply add your API token instead of base64(username:password) :wink: I've updated the docs accordingly.

SHU-red commented 2 years ago

Oh man you are putting so much work into this relaxed

I also have a guess: I defined all of my items via *.items file/script and not GUI. In this case the chance is high, that items can not be changed via API.

I will test

  1. Try to set type/room through sepia for a gui-generated item
  2. Try to add sepia metadata via modifying *.items file

Can you give me a hint what metadata exactly to set? What you saw there was my generic naming of my items. Can you tell me how I can set a "nice name" for using it for commands like "Ambient Light" instead of "dLedStripe_Swt"

Thanks again

OK so just to clarify, i tried to change metadata through Sepia for a GUI-Generated item it worked!

So i think this issue can be closed

Everything works as expected and metadata for Items created in *.items files have to be set there (as all other metadata too)

At the beginning i just was not sure if Sepia is chaning OHs items Metadata or does store its own metadata

Thanks for your support! And yes, token also works for me ;-)

fquirin commented 2 years ago

At the beginning i just was not sure if Sepia is chaning OHs items Metadata or does store its own metadata

If you're having trouble writing data to your smart home HUB there is actually a 2nd option: the SEPIA internal HUB. In this case you create all devices you want to control yourself and just tell SEPIA "how" to control them. This way you can mix different HUBs as well. There is some info about the pros and cons listed in the docs.

And yes, token also works for me ;-)

Nice :-)

SHU-red commented 2 years ago

Just as a reminder I think this topic is solved

Great job @fquirin