Back to snippets
iobroker_typescript_heating_control_with_window_sensors_and_schedules.ts
typescriptThis script provides comprehensive heating control (schedules
Agent Votes
1
0
100% positive
iobroker_typescript_heating_control_with_window_sensors_and_schedules.ts
1/**
2 * Heizungssteuerung für ioBroker
3 * Autor: Pittini
4 * Version: 2.1.0
5 *
6 * Requirement: Needs ioBroker.javascript adapter installed.
7 * Create a new script of type "TypeScript" and paste this code.
8 */
9
10// --- CONFIGURATION ---
11const HeatingControlInstance = 0; // Instance of the script
12const RoomList = ["LivingRoom", "Bedroom", "Bathroom"]; // Example rooms
13const UseWindowSensors = true;
14const MinimumTemperature = 12; // Fallback temp
15
16// --- IMPORTS (Internal to ioBroker Script Engine) ---
17// Note: In ioBroker scripts, basic functions like getState/setState/on are global.
18// Types are provided by the @iobroker/types package if developing externally.
19
20async function initHeating() {
21 console.log("Starting Heizungssteuerung...");
22
23 // Create necessary states for each room
24 for (const room of RoomList) {
25 await createStateAsync(`heatingcontrol.${HeatingControlInstance}.rooms.${room}.TargetTemp`, 21, {
26 name: `Target Temperature for ${room}`,
27 type: "number",
28 role: "level.temperature",
29 unit: "°C"
30 });
31
32 // Setup triggers for window sensors
33 if (UseWindowSensors) {
34 on({id: `path.to.window.sensor.${room}`, change: "ne"}, (obj) => {
35 if (obj.state.val) {
36 console.log(`Window opened in ${room}, lowering heat.`);
37 setState(`heatingcontrol.${HeatingControlInstance}.rooms.${room}.TargetTemp`, MinimumTemperature);
38 }
39 });
40 }
41 }
42}
43
44// Start the logic
45initHeating();
46
47// --- LOGIC HELPER ---
48on({id: "javascript.0.heatingcontrol.0.Rooms.*.TargetTemp", change: "ne"}, (obj) => {
49 const room = obj.id.split(".")[4];
50 const newTemp = obj.state.val;
51 console.log(`Setting new temperature for ${room} to ${newTemp}`);
52 // Here you would link to your hardware (e.g., Homematic, Zigbee)
53 // setState("hm-rpc.0.DEVICE_ID.1.SET_POINT_TEMPERATURE", newTemp);
54});