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

[SRTS-A01](Aqara Smart Radiator Thermostat E1) Added smart schedule support #4763

Closed
wants to merge 7 commits into from

Conversation

artem-sedykh
Copy link
Contributor

No description provided.

@artem-sedykh
Copy link
Contributor Author

image
image

@artem-sedykh artem-sedykh changed the title [SRTS-A01](Aqara Smart Radiator Thermostat E1) Added scheduling support [SRTS-A01](Aqara Smart Radiator Thermostat E1) Added smart schedule support Oct 9, 2022
devices/xiaomi.js Outdated Show resolved Hide resolved
@artem-sedykh
Copy link
Contributor Author

Start and end time duration at least 4 hours

image

The end time must be greater than the start time, minimum duration is one hour
image

devices/xiaomi.js Outdated Show resolved Hide resolved
devices/xiaomi.js Outdated Show resolved Hide resolved
@problem9
Copy link

is this working, will be this merged?

@protyposis
Copy link
Contributor

What is missing to get this merged? What is the general PR review process in this repo?

@Koenkk
Copy link
Owner

Koenkk commented Nov 9, 2022

@artem-sedykh could you add the schedule_settings to the exposes?

@artem-sedykh
Copy link
Contributor Author

I don't know how to do it, now it works via mqtt

@Koenkk
Copy link
Owner

Koenkk commented Nov 9, 2022

@artem-sedykh can you provide me an example on what payload schedule_setting has?

Copy link
Contributor

@protyposis protyposis left a comment

Choose a reason for hiding this comment

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

I am wondering whether the Z2M Frontend supports JSON data, or if the schedule_settings should be additionally stringified to allow modification in the UI.

Comment on lines +101 to +110
const schedule = {
repeat: [],
start: getTime(2),
end: getTime(20),
values: [
{time: getTime(2), temperature: value.readUint16BE(6)/100},
{time: getTime(8), temperature: value.readUint16BE(12)/100},
{time: getTime(14), temperature: value.readUint16BE(18)/100},
],
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This structure contains the start time twice, of which schedule.start is ignored in the toZigbee conversion. This feels unintuitive and is a potential (and avoidable) source of user confusion and error. How about using a structure like the following?

Suggested change
const schedule = {
repeat: [],
start: getTime(2),
end: getTime(20),
values: [
{time: getTime(2), temperature: value.readUint16BE(6)/100},
{time: getTime(8), temperature: value.readUint16BE(12)/100},
{time: getTime(14), temperature: value.readUint16BE(18)/100},
],
};
const schedule = {
repeat: [],
values: [
{time: getTime(2), temperature: value.readUint16BE(6)/100},
{time: getTime(8), temperature: value.readUint16BE(12)/100},
{time: getTime(14), temperature: value.readUint16BE(18)/100},
{time: getTime(20)},
],
};

To better fit the Aqara app's naming, values could also be renamed to actingTimes.

Comment on lines +287 to +294
const getTimeValue = (time) => {
let totalMinutes = time.hours * 60 + time.minutes;
if (time.next_day) {
const offset = 1440 - startTime.hours * 60 + startTime.minutes;
totalMinutes = totalMinutes + offset;
}
return totalMinutes;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be const offset = 1440 - startTime.hours * 60 - startTime.minutes (or use braces instead)?

Also I'm wondering whether this makes sense at all. According to this calculation, "same day" times are absolute (relative to 00:00), while a "next day" time is calculated relatively to the start time. Is this really desired?

throw new Error('"repeat" must have at least one value');
}

const startTime = {...value.values[0].time, next_day: false};
Copy link
Contributor

Choose a reason for hiding this comment

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

In reference to a previous comment: If you keep the current schedule format, it would be helpful to assert that value.from equals value.values[0].time, or a least log a mismatch warning which says that data is inconsistent and that the start time will be ignored.

Comment on lines +265 to +270
let repeat = 254;
for (let i = 1; i <= 7; i++) {
if (value.repeat.some((e) => e.toUpperCase() == dayNames[i - 1].toUpperCase()) == false) {
repeat = repeat & ~(1 << i);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be cleaned up to something like this (better names, simplified expressions, zero-based loop index to better match the parsing code in fromZigbee):

Suggested change
let repeat = 254;
for (let i = 1; i <= 7; i++) {
if (value.repeat.some((e) => e.toUpperCase() == dayNames[i - 1].toUpperCase()) == false) {
repeat = repeat & ~(1 << i);
}
}
const normalizedRepeatDays = value.repeat.map(dayName => dayName.toLowerCase());
let repeat = 0;
for (let i = 0; i < dayNames.length; i++) {
if (normalizedRepeatDays.includes(dayNames[i])) {
repeat = repeat | (1 << i+1);
}
}

or even

Suggested change
let repeat = 254;
for (let i = 1; i <= 7; i++) {
if (value.repeat.some((e) => e.toUpperCase() == dayNames[i - 1].toUpperCase()) == false) {
repeat = repeat & ~(1 << i);
}
}
const normalizedRepeatDays = value.repeat.map(dayName => dayName.toLowerCase());
const repeat = dayNames.reduce((repeat, dayName, index) => {
const isDaySelected = normalizedRepeatDays.includes(dayName);
return repeat | isDaySelected << index+1;
}, 0);

@0ip
Copy link
Contributor

0ip commented Nov 28, 2022

Not much is happening here anymore, unfortunately, but I think the feature is relatively important to many owners of that thermostat, me included.

@protyposis Would it be ok if you open a new pull request based on the excellent work of @artem-sedykh and your suggestions?

Comment on lines +90 to +92
case 0x027d:
result['schedule'] = {1: 'ON', 0: 'OFF'}[value];
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this relate to the preset setting? Shouldn't the schedule be active when preset is set to auto, or does auto mean something different? What happens when I set preset to manual or away, and at the same time schedule to ON?

@protyposis
Copy link
Contributor

@0ip I'd love to but I'm afraid I'm missing the background to be able to decide what makes sense here. The only knowledge I have of Zigbee messages in general and the Aqara TRV specifically is what I read in this PR, and that unfortunately seems insufficient at this point.

@Koenkk
Copy link
Owner

Koenkk commented Nov 30, 2022

@0ip feel free to make a new pr

@0ip
Copy link
Contributor

0ip commented Dec 1, 2022

@Koenkk I find myself in a similar situation as @protyposis, sorry

@protyposis
Copy link
Contributor

Gave it a try anyway: #5058, @Koenkk if you could be so kind and review please :)

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2023

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale label Jan 1, 2023
@Koenkk
Copy link
Owner

Koenkk commented Jan 1, 2023

I believe this one can be closed in favour of #5058

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

Successfully merging this pull request may close these issues.

6 participants