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

danfoss: Add thermostat schedule support #3499

Merged
merged 1 commit into from
Dec 26, 2021

Conversation

kennylevinsen
Copy link
Contributor

@kennylevinsen kennylevinsen commented Dec 12, 2021

Note that I have not tested the popp/hive side of things.

@kennylevinsen kennylevinsen force-pushed the danfoss-schedule branch 2 times, most recently from a9372fd to 99d738b Compare December 12, 2021 08:10
@kennylevinsen kennylevinsen force-pushed the danfoss-schedule branch 2 times, most recently from bc617b1 to e1eeb05 Compare December 12, 2021 14:39
devices/popp.js Outdated
@@ -66,7 +67,9 @@ module.exports = [
.withDescription('Mean radiator load for room calculated by gateway for load balancing purposes (-8000=undefined)')
.withValueMin(-8000).withValueMax(100),
exposes.numeric('load_estimate', ea.STATE_GET)
.withDescription('Load estimate on this radiator')],
.withDescription('Load estimate on this radiator'),
exposes.enum('programming_operation_mode', ea.ALL, ['setpoint', 'schedule'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this expose to exposes.js, could you also improve the description?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this expose to exposes.js

As its own thing or as another withXyz on the climate expose?

could you also improve the description

Sure, but it will be a little wordy.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As its own thing or as another withXyz on the climate expose?

Own thing

Sure, but it will be a little wordy.

No problem, no need to keep things short there.

@kennylevinsen kennylevinsen force-pushed the danfoss-schedule branch 2 times, most recently from 1c30ecb to 4195d18 Compare December 15, 2021 16:56
@Koenkk
Copy link
Owner

Koenkk commented Dec 15, 2021

Looks good to me, if you can fix the merge conflict I can merge it.

@kennylevinsen
Copy link
Contributor Author

Sorry for the delay, rebased!

@Koenkk Koenkk merged commit 172f281 into Koenkk:master Dec 26, 2021
@kennylevinsen kennylevinsen deleted the danfoss-schedule branch December 26, 2021 17:07
@2Max2Pax
Copy link

2Max2Pax commented Jan 17, 2022

Is this issue still open?

I 'm using Zigbee2MQTT version: 1.22.2 commit: 414c51f
In the "dev console" the attribute weekly_schedule (or thermostat_weekly_schedule ) is missing.
What is the correct way (and mask) to set the weekly schedule and read it back?

@kennylevinsen
Copy link
Contributor Author

It is merged and works. You set weekly_schedule over mqtt as an object that looks something like:

{
   days: 0b1111111, // bitmask of days
   mode: 0x1, // heat mode
   transitions: [ // times are minutes since midnight
      {transitionTime: 660, heatSetpoint: 21.5},
      {transitionTime: 1200, heatSetpoint: 18.0},
   ]
}

Remember to change the programming operation mode to schedule for it to work.

@2Max2Pax
Copy link

@kennylevinsen , thank you for the answer.
I published topic:

zigbee2mqtt/trv_studio/set/weekly_schedule

Payoload:

{"days": 0b1111111, "mode": 0x1, "transitions": [{"transitionTime": 660, "heatSetpoint": 21.5},{"transitionTime": 1200, "heatSetpoint": 18.0},]}

Tested also without the comma before ]
I got the following error:

Publish 'set' 'weekly_schedule' to 'trv_studio' failed: 'TypeError: payload.transitions is not iterable'

I also tryed adding "numoftrans":2 to the payload but I always get the same error

@kennylevinsen
Copy link
Contributor Author

For reference, this is the code snippet I used:

const setSchedule = (schedule, days, radiator) => {
	console.log("Setting schedule" + (radiator ? " for " + radiator.key : ""), schedule);
	if (!days) {
		return;
	}

	for (let room_type in schedule) {
		let transitions = schedule[room_type];
		let payload = {
			dayofweek: days, // Already a bitmask
			mode: 0b01,      // Heating
			transitions: transitions.map(t => ({
				transitionTime: timeFromMidnight(t.time),
				heatSetpoint: t.temp,
			})),
		};
		payload.numoftrans = payload.transitions.length; // This should just be deduced by z2m...
		radiatorsForType(room_type)
			.filter(r => !radiator || radiator.key === r)
			.forEach(r => client.publish(r + "/set", JSON.stringify({
				weekly_schedule: payload,
				programming_operation_mode: "schedule",
			})));
	};
};

The error you are getting would be from here, and seems to suggest that either there is no field named "transition" in what you sent, or it is not an array.

If you are sure that you are sending a well-formed JSON serialized message (remember to JSON.stringify), maybe add a log there to see if what the payload contains?

@2Max2Pax
Copy link

I publish MQTT with mosquitto.
I made several tests, changing the value of days: , with or without comma before] in the topic
This is what i get subscribing the topic " zigbee2mqtt/#" :

zigbee2mqtt/trv_studio/set/weekly_schedule {"days": 0b1111111, "mode": 0x1, "transitions": [{"transitionTime": 660, "heatSetpoint": 21.5},{"transitionTime": 1200, "heatSetpoint": 18.0},]}
zigbee2mqtt/bridge/logging {"level":"error","message":"Publish 'set' 'weekly_schedule' to 'trv_studio' failed: 'TypeError: payload.transitions is not iterable'"}

I do not use java, so I do not use stringify.

in the whole log file, all the entries about weekly schedule look like:

�[31mZigbee2MQTT:error�[39m 2022-01-17 15:43:57: Publish 'set' 'weekly_schedule' to 'trv_studio' failed: 'TypeError: payload.transitions is not iterable'

@kennylevinsen
Copy link
Contributor Author

If that is what z2m is logging, then what you are sending is not valid JSON. What I quoted is JavaScript, and you need to serialize it as JSON first.

It should be enough to convert the binary and hex notated numbers to decimal and remove the trailing comma.

@2Max2Pax
Copy link

Oooops, you are right. I just realized that in the test with decimal I made a typo ... corrected. No errors anymore.

Now, I still miss 2 points:

  1. How can I read back the weekly schedule?
  2. If I want to make a different schedule for each day (or group of days) of the week, should I publish as many payloads as the dyas or group of days?

@kennylevinsen
Copy link
Contributor Author

  1. You should be able to "get" the field as well.
  2. Yes, write per schedule group you need. Note that any day included in a write is wiped of its previous schedule - there can only be one.

@2Max2Pax
Copy link

I made some tests and I could not find a way to read back the weekly schedule. I suppose I do not use the correct payload or Z2M doesn't get correct data or doesn't expose it at all.

I noticed that I cannot set more than 6 transitions: Z2M doesn't return any error but the TRV simply doesn't apply any transition.
Changing numberOfWeeklyTrans and/or numberOfDailyTrans in the dev.console generates the following error:

Publish 'set' 'write' to 'trv_studio' failed: 'Error: Write 0x804b50fffe3da0a8/1 hvacThermostat({"numberOfDailyTrans":6,"numberOfWeeklyTrans":42}, {"sendWhenActive":true,"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Status 'READ_ONLY')'

So there is no chance to use 7 or more transistions.

I'm going to test separate weekly schedule for today and tomorrow and see if it works.

@kennylevinsen
Copy link
Contributor Author

The numberOfXYZTrans fields tell you what the device limitation is - they are not something you can change. Doing more than 6 transitions in a day does seem aggressive for a thermostat considering the thermal mass of a room/home.

As for getting the weekly schedule, that may be a device bug. I recall someone saying that Danfoss thermostats only reply with their weekly schedule when asked solely for heat schedule, instead of all schedules as z2m asks. Not something I have tested. Would require a Danfoss quirk.

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

Successfully merging this pull request may close these issues.

4 participants