jaroschek / home-assistant-myuplink

Custom Home Assistant integration for devices and sensors in myUplink account.
44 stars 10 forks source link

Possibility to show and set smarthome mode? #153

Open Linqman opened 2 months ago

Linqman commented 2 months ago

Hi, and thank you for your work on this integration!

I have a question regarding the getting and setting of smart home mode for my F750, is this something that is supported? On the public API swagger, you can query the current mode, and also set it, but I can't seem to find the setting in home assistant. GET /v2/systems/{systemId}/smart-home-mode

jaroschek commented 1 month ago

@Linqman The smart home mode is currently not supported in this integration.

But to be honest, I am already working on it...

I just have some issues working with it. There is a schema definition of the available values, that would lead to a select entity:

smart home mode schema definition

But not all defined options seem to be valid values for the PUT request:

failed to put 'Home'

What values are you able to PUT there? Which values would be acceptable? Or are the possible values related to the users system(s)/device(s)?

Unfortunately this is another example of the bad implementation/usage of the myUplink API besides missing and wrong parameter definitions like false writable and others.

jaroschek commented 1 month ago

From the 5 defined options I can only use 3 effectively:

Linqman commented 1 month ago

I had a similar experience when testing last time, I only got it to Away mode, but nothing after that. However, now when I tested I got i set to Vacation, but nothing else after that.

If I remember correctly from the NibeUplink API, the smart home mode worked so that when selecting the modes "Away" or "Vacation" (I just used "Vacation"). What it actually did was set the mode, and after about an hour (I don't remember the specific duration), it reverted back to Home/Default/Normal mode.

But if you called the API again, it would restart the internal timer, and keep the system in vacation mode for another hour. To actually use this, I had an automation that updated the vacation mode in Nibe every half-an-hour when a vacationmode boolean was set to true. And when you wanted to get out of vacation mode, you just stopped setting it, and it would revert in a maximum of an hour.

So I guess it works the same here, and if I would guess about the reasons for why, it might be that in case the internet connection dies while in away mode, it won't get stuck in that.

But I agree with you that there's no explanation for this behaviour.

jaroschek commented 1 month ago

Ok, sounds like an experiment. Knowing of this previous behaviour I decided to give it a try.

I have created a new pre-release that you can test and check if it works for you: https://github.com/jaroschek/home-assistant-myuplink/releases/tag/1.4.0-rc1

Linqman commented 1 month ago

Thanks! I'll test it out right away!

Linqman commented 1 month ago

Hi, the smart home mode just shows up as unavailable: image

jaroschek commented 1 month ago

How many devices do you have in your myuplink system? And is this device connected?

If you have only a single device in the system, the smart home mode entity will only be available if the device is connected.

I tried to set the value while the device was disconnected and got an error in response because of the disconnected device.

Linqman commented 1 month ago

I have only one device, and it is connected to myuplink. I get all other data from it.

Den ons 18 sep. 2024 kl 13:57 skrev Stefan Jaroschek < @.***>:

How many devices do you have in your myuplink system? And ist this device connected?

If you have only a single device in the system, the smart home mode entity will only be available if the device is connected.

I tried to set the value while the device was disconnected and got an error in response because of the disconnected device.

— Reply to this email directly, view it on GitHub https://github.com/jaroschek/home-assistant-myuplink/issues/153#issuecomment-2358156128, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWSNPAZ24WQC5BYGSOFJ56LZXFMB5AVCNFSM6AAAAABOJZ5JM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJYGE2TMMJSHA . You are receiving this because you were mentioned.Message ID: @.***>

jaroschek commented 1 month ago

Can you please show the current response from GET /v2/systems/{systemId}/smart-home-mode?

Linqman commented 1 month ago

image

jaroschek commented 1 month ago

Thank you! It looks the same like my response.

Did you restart your Home Assistant completely?

Linqman commented 1 month ago

Actually now the smart home mode has shown up, and yes I did restart it after installing the new version. I'll check to see if I can see when it got the statuses.

Linqman commented 1 month ago

I tried setting the Smart Home Mode to Vacation, which worked, my heatpump went into vacation mode. But after that, presumably on next reading of data, all entities went to unavailable. Then the next minute, presumably next reading of data, the entities again had values, but the smart home mode showed "Normal", even though the heat pump was still on vacation mode.

The problem with the wrong state of smart home mode seems to be the API. I checked and the API returns status "Normal" even though the heatpump shows vacation mode.

Linqman commented 1 month ago

I did some more testing. It appears the heatpump reacts immediately to the set smart home status calls, but the get smart home status lags behind. Here's what I tried and observed

21:00 set to Default -> heatpump immediately updated 21:01 Smart Home Mode changed to Normal 21:03 set to Vacation -> heatpump immediately updated 21:15 Smart Home Mode changed to Vacation 21:16 set to Normal -> heatpump immediately updated (smart home mode shows Vacation) 21:19 set to Away -> heatpump immediately updated (smart home mode shows Vacation) 21:20 set to Normal -> heatpump immediately updated (smart home mode shows Vacation) 21:32 Smart Home Mode changed to Normal

jaroschek commented 1 month ago

Do you still have the problem with the temporarily unavailable entities? If so can you check the connection state entity of the device? If the device is (temporarily) disconnected, you could activate the config option Keep disconnected parameters available?.

Regarding the lag in the API there is nothing I can do. Or does the API return the correct value immediately but the Integration in Home Assistant lags?

Linqman commented 1 month ago

No, the entities have not gone unavailable now.

Yeah, I know you can't affect the API, it is the API that reports the old status. It actually seems to update 4 times an hour, and at least these two days, it seems to happen at the same minutes of each hour.

Could be a possibility to change the implementation so that one entity would just be an option to set the mode, and another one would display the value from the API.

jaroschek commented 1 month ago

No, the entities have not gone unavailable now.

Great!

Could be a possibility to change the implementation so that one entity would just be an option to set the mode, and another one would display the value from the API.

This would be complicated. For example what should happen If someone changes the smart home mode outside of Home Assistant? In such a case both entities would have to be updated to show the new state.

Currently I would make one step after the other and finalize this release in the way it is implemented now. (Hopefully myUplink is working to mat the API more reliable.)

Linqman commented 1 month ago

I now enabled the "Keep disconnected parameters available" setting, as the connection state also indicates it once in a while gets disconnected: image

Yes it would of course be more complicated, but my thought was that you would have a "Set smart home mode" entity (or service) that just sets the mode, never updates with the status of the smart home mode. Then another one "Reported smart home status" or something, that would update whenever the API actually updates.

I think it might be some API call throttling that causes the connection to get disconnected. When testing the mode changes while standing beside my heatpump, I got it to disconnect several times when changing smart home modes, and I suspect this happens when you happen to change the mode through the API close enough to the previous calls to the API.

image

And btw., this current implementation is all I need and I'm very grateful for it. I'm just testing to try and understand how their API works. I also asked Nibe but they said they have no support for the open API :(