Plugwise: set schedule

Plugwise has a service for climate.set_hvac_mode, but it doesn’t have any service to change the active schedule. The documentation mentions an awkward way to do it (Plugwise - Home Assistant) but this can not be used in automations.

Since it can be done remotely, I assume the issue is not in the api or the plugwise python component, but simply that it hasn’t been implemented yet. Looking at the source I can’t figure out how to do it via the api though (there only seems to be a ‘get’ for the schedules).

At the moment only the active schedule can be turned off and on, and the previously active schedule can be turned on.

I have been thinking of adding this feature (fellow code-owner of Core plugwise / plugwise-beta :slight_smile: ) but there is nothing in the User Interface that can use this feature.
It could be done via a service call but then the user would need to input the Schedule name. That makes it unnecessarily complex in my mind.

It is now also possible to create an automatically filled input_select (not sure if it is called that when it is provided by an integration, maybe just select?). In the attributes right now is all the available names isn’t there? So it would be possible to create an extra entity as well.

I also don’t think it is that big a deal that it needs a valid name, there’s many service calls that don’t work if you put in the wrong data. As an MVP at least all that is needed is the possibility to set the schedule via the api I guess, the rest can follow (and I can possibly write my own PR for).

[edit] Looks like it is indeed select, here’s an example for the logitech harmony integration.:

Please add a feature request at GitHub - plugwise/plugwise-beta: Custom-component / development version of the Plugwise Home Assistant platform

And thanks for the pointer!

Or, if you feel up to it, create PR’s at both GitHub - plugwise/python-plugwise: Plugwise module for Smiles (Anna, Adam, P1), Stretch and USB-stick and the above one :slight_smile:

After looking at the python-plugwise code, it already supports setting a different schedule.

But HA Core does not have a matching climate set service call. It would have to become a plugwise-specific service call.

Good call, didn’t know Select Entity | Home Assistant Developer Docs existed :slight_smile:

A quick look at the python plugwise code I came to the same conclusion. I noticed the following functions:

    async def set_schedule_state(self, loc_id: str, name: str, state: str) -> bool:
        """Set the Schedule, with the given name, on the relevant Thermostat.
        Determined from - DOMAIN_OBJECTS.


    def _schemas(self, location: str) -> tuple[str, ...]:
        """Helper-function for _device_data_climate().
        Obtain the available schemas/schedules. Adam: a schedule can be connected to more than one location.
        NEW: when a location_id is present then the schedule is active. Valid for both Adam and non-legacy Anna.

This last one appears to be used when the device list is filled (since the underscore implies I assume that it shouldn’t be used directly).

So that leaves the question on how best to implement it. a select entity is probably the easiest (I think I might be able to figure it out), but the documentation Tom linked does say the following:

This entity should only be used in cases there is no better fitting option available. For example, a bulb can have user selectable light effects. While that could be done using this select entity, it should really be part of the light entity, which already supports light effects.

That sortof implies that it should first be included in the climate entity and then added to the plugwise integration? Just adding a select seems like a lot less of a hassle though.

You are looking at the wrong code. The service will need to be implemented in the plugwise-beta or the Core plugwise code. That code will call the necessary function(s) from the plugwise-library code that you show above. I think Tom has planned to try building something during the coming day(s).

You can look at plugwise-beta/ at 46410d10ac35e86579aac7a7f261227f0fbf3b3d · plugwise/plugwise-beta · GitHub to see how the delete_notification service has been implemented.
Please note: there also needs to be something related in the services.yaml file.

I think there’s some confusion, I realise that it needs to be done on the integration side, I just wanted to double-check that these functions in the package were the correct ones, since the integration will have to call these functions won’t they?

Yes, the first function will be needed. But not the 2nd. The list of available schedules is in the output of the plugwise backend. Look at plugwise-beta line 144 on how to find them.

Schema service by CoMPaTech · Pull Request #251 · plugwise/plugwise-beta · GitHub in progress

Works on my environment (rather hard to functionally test without writing a lot of test-related code).

wow, that was fast :slight_smile:
Do I understand correctly that I can test it by temporarily installing the beta integration via HACS, or do I need to delete the core version for that?

No, when you install the Plugwise-beta custom_component it overrides the Core Plugwise component.
There are 100% compatible, when both have the same code-base.

This is how it looks for my Anna :slight_smile:

Nice, looks like it works as intended :slight_smile:

@sophof It should be fully working in pw-beta v0.22.0a1. There is a bug in v0.21.6.

Looks like that hasn’t been merged into the main branch yet, I think I’ll wait for that.

This test-version was made specifically for you and another user who requested the changes.
It was already tested by Tom and me.
But more people should test before we merge the changes into the plugwise-beta main branch.
Preferably the requester(s) of the changes.

Ok, just to be clear, I should be using the url right?