-
Notifications
You must be signed in to change notification settings - Fork 8
Example Thermostat
When you work with ioBroker.bshb you will often see states of type object
. This has several reasons.
One reason is that the content of these objects is often not stable and would require dynamic creation of objects.
Secondly, the adapter treats all Bosch devices the same, so that for example no distinction is made between thermostat or motion detector. This has the advantage that the adapter should also be compatible with new devices in the future.
This example will use the Bosch thermostat to show how these values can be handled.
In the picture below we see that our roomClimateControl for our living room has the value schedule
of type object
.
In this example we use the ioBroker.javascript adapter to create our logic. There are also other adapters like Node-RED which are also possible. If you are not familiar with JavaScript or programming at all I would actually recommend Node-RED.
The first step is that we first try to read the content from the schedule object. Therefore, we open the javascript adapter and create a new TypeScript script with the following content:
const obj = getState('bshb.0.roomClimateControl_hz_2.RoomClimateControl.schedule');
console.log(JSON.stringify(obj));
If you start the script now we get an unformatted JSON text as output. The best thing to do now is to use a tool to format the content and make it more readable.
Below is a small excerpt:
{
"val":{
"profiles":[
{
"switchPoints":[
{
"startTimeMinutes":0,
"value":{
"@type":"temperatureLevelSwitchPointValue",
"temperatureLevel":"ECO"
}
},
{
"startTimeMinutes":360,
"value":{
"@type":"temperatureLevelSwitchPointValue",
"temperatureLevel":"COMFORT"
}
}
],
"day":"MONDAY"
},
{
"switchPoints":[
{
"startTimeMinutes":0,
"value":{
"@type":"temperatureLevelSwitchPointValue",
"temperatureLevel":"ECO"
}
}
],
"day":"TUESDAY"
}
]
},
"ack":true,
"ts":1580220124954,
"q":0,
"from":"system.adapter.bshb.0",
"user":"system.user.admin",
"lc":1580220120244
}
So we have a list (array) under the property "profiles", which in turn contains objects. These objects always have the properties "switchPoints" and day. etc.
In summary, we see that for each day of the week we have several points in time where at a certain minute of the day the temperature is switched between ECO and COMFORT.
Now we want to change the value of our schedule state. Therefore, we start with a small script which just listens to changes of a created userdata state with a boolean type.
To create this state we simply select 0_userdata.0 in ioBrokers objects view and then click on the add (plus) button. The name in this example is "home" and as mentioned it should be of type boolean.
Then we create a new script in which we want to listen to changes of this state and then print "home" or "not home" depending on the value.
on({id: "0_userdata.0.home", change: "any"}, (obj) => {
if(obj.state.val === true) {
console.log("home");
} else {
console.log("not home");
}
});
You can test this by changing the value in ioBrokers object view.
Okay so far so good. The next step is to actually change the value. We don't have to change that much. We define a variable "schedule" in which we store the configuration of our thermostat depending on the value "home". Then we only set the value schedule of our room climate control and we are done.
For the sake of clarity, I have removed everything except Monday in the example.
function getAwaySchedule() {
return {
"profiles": [
{
"switchPoints": [
{
"startTimeMinutes": 0,
"value": {
"@type": "temperatureLevelSwitchPointValue",
"temperatureLevel": "ECO"
}
},
{
"startTimeMinutes": 360,
"value": {
"@type": "temperatureLevelSwitchPointValue",
"temperatureLevel": "COMFORT"
}
},
{
"startTimeMinutes": 1320,
"value": {
"@type": "temperatureLevelSwitchPointValue",
"temperatureLevel": "ECO"
}
}
],
"day": "MONDAY"
}
]
};
}
function getHomeSchedule() {
return {
"profiles": [
{
"switchPoints": [
{
"startTimeMinutes": 0,
"value": {
"@type": "temperatureLevelSwitchPointValue",
"temperatureLevel": "ECO"
}
},
{
"startTimeMinutes": 500,
"value": {
"@type": "temperatureLevelSwitchPointValue",
"temperatureLevel": "COMFORT"
}
},
{
"startTimeMinutes": 1320,
"value": {
"@type": "temperatureLevelSwitchPointValue",
"temperatureLevel": "ECO"
}
}
],
"day": "MONDAY"
}
]
};
}
on({id: "0_userdata.0.home", change: "any"}, (obj) => {
let schedule;
if (obj.state.val === true) {
schedule = getHomeSchedule();
} else {
schedule = getAwaySchedule();
}
setState("bshb.0.roomClimateControl_hz_2.RoomClimateControl.schedule", schedule);
});
Tip 1. Change bshb adapter log level to debug so that you can see that something is happening. Controller should confirm request with 204.
Tip 2. Configure the profile in the Bosch Smart Home App and then read out the values.