tschamm / boschshcpy

Bosch Smart Home Controller API Python Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error 400 while creating a new Session

tfo-inc opened this issue · comments

Hello

im out of ideas. Im Trying to connect to my controller with a python script. My Script looks the following:`

#!/usr/bin/env python3
"""
This script is used to set the temperature of the room to 18 degrees.
To run this script you first have to import the library boscshcpy with the command: pip3 install boschshcpy.

Other Prerequisites:
- The client certificate and key must be in the same directory as this script.
- The client certificate and key must be named "client-cert.pem" and "client-key.pem".
- The client certificate and key must be in PEM format.
- Depending on the room you want to change the temperature you need to change session.device('roomClimateControl_hz_1') to the responding room.
"""
import boschshcpy
import sys
import os

NewTempTemp = 22

def CreateSessionAndSendNewTemp(NewTemp):
  #Create session and send new Temp for the room
  session = boschshcpy.SHCSession(controller_ip="172.16.16.20", certificate='/home/pi/BoschKalender/Raumbuchung/client-cert.pem', key='/home/pi/BoschKalender/Raumbuchung/client-k>  device = session.device('roomClimateControl_hz_3')
  service = device.device_service('RoomClimateControl')
  service.setpoint_temperature = NewTemp

def CreateSessionAndCompareTemp():
   #Create session and send new Temp for the room
  session = boschshcpy.SHCSession(controller_ip="172.16.16.20", certificate='/home/pi/BoschKalender/Raumbuchung/client-cert.pem', key='/home/pi/BoschKalender/Raumbuchung/client-k>  device = session.device('roomClimateControl_hz_3')
  service = device.device_service('RoomClimateControl')
  OldTemp = service.setpoint_temperature
  print(OldTemp)
  if OldTemp < NewTempTemp:
    CreateSessionAndSendNewTemp(NewTempTemp)

try:
  CreateSessionAndCompareTemp()
except:
  sys.exit(1)

If i run the script i get the following output:

ERROR:root:Body: None ERROR:root:Headers: {'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'api-version': '2.1', 'Content-Type': 'application/json'} ERROR:root:URL: https://172.16.16.20:8444/smarthome/information ERROR:root:Failed to get information from SHC controller: SHC Error (message: API call returned non-OK result (code 400)!: b'')

This script was working for almost two years now. After the heating break in summer i reactivated the script and now it dosn´t work anymore.

So far i have tried:

  1. Readding the Client.
  2. New Certificates. --> The same certificates work for postman
  3. Shrinking the script to the bare minimum: only the new Session but the same error.

Does anyone face the same issue ore has an idea what my problem might be?

Thanks in advance
Theo

Hey, what version of the boschshcpy library are you using? There has been an update in the Bosch API, so you need to update the library.

Apparently i was still on 0.2.43. Currently in the progress of updating my python to support version 0.2.72.

Thanks. Will give an update if Version 0.2.72 fixes my problems.

So after updating Python and the Bosch API, the Script works again.

For anyone using this on an PI. You need to use pyenv. Also use rustup.rs to install rust.
After updating python and rust you can update boschshcpy to the latest version.