-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
is this working, will be this merged? |
What is missing to get this merged? What is the general PR review process in this repo? |
@artem-sedykh could you add the |
I don't know how to do it, now it works via mqtt |
@artem-sedykh can you provide me an example on what payload |
There was a problem hiding this 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.
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}, | ||
], | ||
}; |
There was a problem hiding this comment.
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?
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
.
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; | ||
}; |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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.
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); | ||
} | ||
} |
There was a problem hiding this comment.
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
):
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
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); |
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? |
case 0x027d: | ||
result['schedule'] = {1: 'ON', 0: 'OFF'}[value]; | ||
break; |
There was a problem hiding this comment.
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
?
@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. |
@0ip feel free to make a new pr |
@Koenkk I find myself in a similar situation as @protyposis, sorry |
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 |
I believe this one can be closed in favour of #5058 |
No description provided.