Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set program with Viessman Vitodens 100w #240

Open
hnykda opened this issue Dec 29, 2021 · 10 comments
Open

Cannot set program with Viessman Vitodens 100w #240

hnykda opened this issue Dec 29, 2021 · 10 comments

Comments

@hnykda
Copy link

hnykda commented Dec 29, 2021

Hi. I have a E3_Vitodens_100_0421 and I am trying to set active programs. The programs seem to be available via circuit.getPrograms(), but I cannot set them apparently. Do you happen to know if this a limitation of Viessman API or can something be done about it? It's really limiting, as what I would want to do is to e.g. set up the gas boiler to go to reduced program when no one is at home, but at the moment I can only use circuit.setMode which basically only has off (~standby) or on. An alternative is to set comfort, normal and reduced temperatures to the same (low) value and then bring them back again.

from PyViCare.PyViCare import PyViCare


def circuit_factory():
    client_id = "<clientid>"
    email = "email"
    password = "<passwd>"

    vicare = PyViCare()
    vicare.initWithCredentials(email, password, client_id, "token.save")
    device = vicare.devices[0]
    
    t = device.asAutoDetectDevice()
    c = t.circuits[0]
    # c.getPrograms()
    return c

circuit = circuit_factory()
circuit.getPrograms()

spits out:

['active',
 'comfort',
 'forcedLastFromSchedule',
 'noDemand',
 'normal',
 'reduced',
 'standby',
 'summerEco']

but when I try to activate it:

In [34]: circuit.activateProgram("reduced")
---------------------------------------------------------------------------
PyViCareCommandError                      Traceback (most recent call last)
<ipython-input-34-b9844e52a4be> in <module>
----> 1 circuit.activateProgram("reduced")

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareDevice.py in activateProgram(self, program)
    415 
    416     def activateProgram(self, program):
--> 417         return self.service.setProperty(f"heating.circuits.{self.circuit}.operating.programs.{program}", "activate", {})
    418 
    419     def activateComfort(self):

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareCachedService.py in setProperty(self, property_name, action, data)
     27 
     28     def setProperty(self, property_name, action, data):
---> 29         response = super().setProperty(property_name, action, data)
     30         self.clear_cache()
     31         return response

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareService.py in setProperty(self, property_name, action, data)
     50 
     51         post_data = data if isinstance(data, str) else json.dumps(data)
---> 52         return self.oauth_manager.post(url, post_data)
     53 
     54     def fetch_all_features(self) -> Any:

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareAbstractOAuthManager.py in post(self, url, data)
     89             self.__handle_expired_token(response)
     90             self.__handle_rate_limit(response)
---> 91             self.__handle_command_error(response)
     92             return response
     93         except TokenExpiredError:

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareAbstractOAuthManager.py in __handle_command_error(self, response)
     65 
     66         if("statusCode" in response and response["statusCode"] >= 400):
---> 67             raise PyViCareCommandError(response)
     68 
     69     """POST URL using OAuth session. Automatically renew the token if needed

PyViCareCommandError: (PyViCareCommandError(...), 'Command failed with status code 502. Reason given was: COMMAND_NOT_FOUND')

interestingly, when I try to activate comfort, I get a different error:

In [35]: circuit.activateProgram("comfort")
---------------------------------------------------------------------------
PyViCareCommandError                      Traceback (most recent call last)
<ipython-input-35-7392f61fb00c> in <module>
----> 1 circuit.activateProgram("comfort")

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareDevice.py in activateProgram(self, program)
    415 
    416     def activateProgram(self, program):
--> 417         return self.service.setProperty(f"heating.circuits.{self.circuit}.operating.programs.{program}", "activate", {})
    418 
    419     def activateComfort(self):

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareCachedService.py in setProperty(self, property_name, action, data)
     27 
     28     def setProperty(self, property_name, action, data):
---> 29         response = super().setProperty(property_name, action, data)
     30         self.clear_cache()
     31         return response

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareService.py in setProperty(self, property_name, action, data)
     50 
     51         post_data = data if isinstance(data, str) else json.dumps(data)
---> 52         return self.oauth_manager.post(url, post_data)
     53 
     54     def fetch_all_features(self) -> Any:

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareAbstractOAuthManager.py in post(self, url, data)
     89             self.__handle_expired_token(response)
     90             self.__handle_rate_limit(response)
---> 91             self.__handle_command_error(response)
     92             return response
     93         except TokenExpiredError:

~/.cache/pypoetry/virtualenvs/vicare-5rfMLF8Q-py3.9/lib/python3.9/site-packages/PyViCare/PyViCareAbstractOAuthManager.py in __handle_command_error(self, response)
     65 
     66         if("statusCode" in response and response["statusCode"] >= 400):
---> 67             raise PyViCareCommandError(response)
     68 
     69     """POST URL using OAuth session. Automatically renew the token if needed

PyViCareCommandError: (PyViCareCommandError(...), 'Command failed with status code 502. Reason given was: COMMAND_NOT_EXECUTABLE')

Any ideas? Thanks!

@cagnulein
Copy link
Contributor

I saw a similar behaviour: in my setup i'm not changing the mode anymore but i'm acting directly on the setpoint. If you want I can share the automation @hnykda

@hnykda
Copy link
Author

hnykda commented Dec 20, 2022

Hey. Thanks for the offer, I have solved that by using pyscript (very easy, actually) setting the setpoints directly as well, so I'm fine, thanks!

@stef-g
Copy link

stef-g commented Dec 27, 2022

I saw a similar behaviour: in my setup i'm not changing the mode anymore but i'm acting directly on the setpoint. If you want I can share the automation @hnykda

@cagnulein @hnykda Same problem here. Would you mind sharing your automation to directly set the setpoints? Thanks!

@hnykda
Copy link
Author

hnykda commented Dec 27, 2022

Sure!

  1. install HACS if you don't have it already
  2. install pyscript via HACS
  3. move https://gist.github.com/hnykda/03c3b7c3cab328223651e58bc6c7e899 to /config/pyscript/vicare_manual_set.py

then you can use it as a service like this:

    service: pyscript.set_default_temperatures
    data:
      reduced: 12
      normal: 18
      comfort: 20

@stef-g
Copy link

stef-g commented Dec 27, 2022

Perfect, works beautifully. I have two heating circuits and created two scripts, so I have a separate service per circuit.
Thanks for your help!

@hnykda
Copy link
Author

hnykda commented Dec 27, 2022

No worries, happy to help. FYI it would be nicer if you added that circuit as a function parameter instead of having two files 🙈

@BrechtMo
Copy link

BrechtMo commented May 14, 2023

Hi, just a small question you might have experience with. After API issues I had to remove the vicare_token.save file and reload the vicare integration in HA.
The vicare integration works fine now but I get this error for vicare_manual_set.
It seems like pyscript is using another token file but I don't know where that is stored.

Exception in </config/pyscript/vicare_manual_set.py> line 27: circuit = circuit_factory() ^ PyViCareInvalidDataError: {'viErrorId': 'req-fc4cdd27e51c47c7b3b59237deab4b2c', 'statusCode': 401, 'errorType': 'UNAUTHORIZED', 'message': 'Request contain invalid token', 'error': 'NO TOKEN AVAILABLE'}

I'll answer my own question: I changed a line in the script, modifying the name for the token.
vicare.initWithCredentials(email, password, client_id, "tokenpyscript.save")
I think both the vicare integration and vicare_manual_set were accessing the same token file.

@hnykda
Copy link
Author

hnykda commented May 14, 2023

Aha! That might be the issue I have been seeing in my installation for the last couple of days. Thanks for the tip, I will monitor if that helps.

@fdmekinabo
Copy link

In my experience I can activate comfort or eco mode, but not normal. What I did, to get normal, was a script where eco mode if activated and then deactivated. Then it goes to normal.

@BrechtMo
Copy link

BrechtMo commented Dec 9, 2023

since I upgrade my home assistant (I think) I'm having issues where the command to change the temperatures often doesn't work. This error is logged


 ERROR (MainThread) [custom_components.pyscript.file.vicare_manual_set.set_default_temperatures] Exception in <file.vicare_manual_set.set_default_temperatures> line 58:
            _set_program_temperature(NORMAL, normal)
                                             ^
JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants