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

fix: restore sh1btabb spec, add a7sghmms #5567

Merged
merged 9 commits into from
Mar 15, 2023
Merged

Conversation

drakhart
Copy link
Contributor

Apply fixes as discussed in #4929

  • Restore sh1btabb spec using minutes, added conversion from GMT+8 to local timezone.
  • Add a7sghmms spec using seconds and local timezone.
  • Small refactor: added constants, removed magic numbers...

devices/giex.js Outdated
case dataPoints.giexWaterValve.irrigationEndTime:
return {[keys.giexWaterValve.irrigationEndTime]: timezone ? toLocalTime(value, timezone) : value};
case dataPoints.giexWaterValve.lastIrrigationDuration:
return {[keys.giexWaterValve.lastIrrigationDuration]: value.split(',').shift()}; // Remove meaningless ,0 suffix
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: for _TZE200_a7sghmms I've always seen ,0 (i.e. 00:02:10,0 instead of a proper fraction of a second, that's why I'm removing this.

@drakhart drakhart marked this pull request as draft March 11, 2023 23:36
@drakhart
Copy link
Contributor Author

I'm converting this to draft until we clarify this doubt about model names (the current ones in the PR are quite unfriendly): #4929 (comment)

@WhimsySpoon
Copy link

WhimsySpoon commented Mar 12, 2023

@drakhart I've tried the new file as a custom converter and have noticed a couple of issues on a QT06 (sh1btabb):

  • The device image no longer appears in the Z2M interface
  • The irrigation_start_time and irrigation_end_time are now GMT+1 (I'm GMT local)

Everything else looks great and it's correctly identified as a model QT06 (sh1btabb) in the UI.

@WhimsySpoon
Copy link

WhimsySpoon commented Mar 12, 2023

@drakhart I don't know why, but changing the year in the toLocalTime function from 1970 to 1900 fixes my timezone issue.

So line 18 becomes:

const local = new Date(`1900-01-01T${time}.000${timezone}`);

@drakhart
Copy link
Contributor Author

drakhart commented Mar 12, 2023

  • The device image no longer appears in the Z2M interface

This is most likely related to the change in model names, as well as the broken documentation link I mention in this comment: #5567 (comment)

I guess we'll need to create new markdown files and images into the zigbee2mqtt.io repo.

  • The irrigation_start_time and irrigation_end_time are now GMT+1 (I'm GMT local)

That's weird. With this conversion I'm getting exactly 7 hours less than the time reported by the device, which is the proper one for me (I'm on CET / GMT+1).

The 1900 fix sounds a bit hacky to me since Unix epoch starts in January 1st 1970, and also feels flaky because setting that I get a weird time difference (i.e. it converts 13:25:08 to 05:10:08 instead of he correct 06:25:08).

Can you please check the system time on the machine you're running Z2M in, and make sure it's set to the proper timezone? Example:

❯ date
Sun Mar 12 13:16:58 CET 2023

@WhimsySpoon
Copy link

Agreed on the hackiness; I can't explain why it makes a difference. I did some debugging and the timezone is GMT+8 (I'm in GMT) and the time was coming through as 8 hours from now.

I'm running Z2M Add-on in Home Assistant OS and the time is correct:

image

@drakhart
Copy link
Contributor Author

This feels very, very weird. Would you mind putting a year somewhere in the middle of epoch time, let's say 2000, instead of 1900 or 1970? Just to make sure this is not some edge case caused by the conversion returning a value below epoch's minimum date.

@WhimsySpoon
Copy link

I changed it to:

const local = new Date(`2000-01-01T${time}.000${timezone}`);

And it's calculating the timezone correctly. I don't understand it. The code as is, with 1970, works perfectly outside of this environment.

@drakhart
Copy link
Contributor Author

I can't explain it either, just wanted to make sure. But seeing that 2000 works properly for both you and me I'll assume that it will also work for people in other timezones, so I'll apply it to the PR.

@WhimsySpoon
Copy link

Sounds good. Happy to test anything else as needed.

@drakhart drakhart marked this pull request as ready for review March 12, 2023 15:40
@drakhart drakhart requested a review from Koenkk March 12, 2023 15:40
@drakhart
Copy link
Contributor Author

Opened the following PR for the docs & images: Koenkk/zigbee2mqtt.io#1947

@drakhart drakhart requested a review from Koenkk March 13, 2023 19:02
@WhimsySpoon
Copy link

I've tested the current changes and the irrigation_end_time no longer changes to --:--:-- when the tap is open.

Instead, when the tap opens, the irrigation_end_time is the irrigation_start_time \ now plus one minute.

@drakhart
Copy link
Contributor Author

I've tested the current changes and the irrigation_end_time no longer changes to --:--:-- when the tap is open.

Instead, when the tap opens, the irrigation_end_time is the irrigation_start_time \ now plus one minute.

It's happening for me too and I didn't notice, thanks for the heads up. It's really weird though, let me look into it.

@WhimsySpoon
Copy link

I did have a brief go at debugging but didn't have enough time. All I can be sure of is that it's not making into the function that converts the time to local.

@drakhart
Copy link
Contributor Author

drakhart commented Mar 13, 2023

I'm getting the following behaviors:

  • If I turn it on with the physical button on the device end time is --:--:-- until I press it again, as expected.
  • If I turn it on from Z2M in capacity mode the end time is also --:--:--, as expected (it doesn't know how much time will it take to serve X litres).
  • If I turn it on from Z2M in duration mode the end time is start time + duration, unless I manually stop it (it then updates to the new end time). I'm not sure, but I'd say this is expected too: it's smart enough to know the end time.

All in all, I don't see anything unusual.

Are you sure it doesn't get into the toLocalTime function? It works fine in my system if I change the model names (I don't own the GMT+8 model, so I need to force it somehow).

@WhimsySpoon
Copy link

WhimsySpoon commented Mar 14, 2023

I'll need to double check when I get home tonight, but previous versions definitely had the end time as dashes whilst the tap was open. I'll have a play later and see if I can find out where irrigation_start_time+00:01:00 is getting injected.

@Koenkk
Copy link
Owner

Koenkk commented Mar 14, 2023

Looks good now, please let me know once this is ready for merge.

@WhimsySpoon
Copy link

WhimsySpoon commented Mar 15, 2023

@drakhart Apologies for the delay on this one. I've conducted some thorough testing and was really struggling to get my head around this. I effectively debugged each line of relevant code to see where it was getting overwritten, but could never see where --:--:-- was being lost.

I then decided to roll-back to the previous version of the converter, and it was still doing it! I went as far as pulling the converter entirely. Still doing it. I then wondered if it was something set on the device itself, so I removed and repaired it. Still doing it.

After sleeping on the issue, I then toggled the mode which had at some point been set back to duration. Changing it back to capacity had it working back again, showing --:--:-- in irrigation_end_time. It seems that having mode set to duration and irrigation_target at 0 meant that the irrigation_end_time would behave as I discovered above.

My huge apologies, @drakhart, there was nothing wrong with your code at all. I've just tested the latest code in this PR and it's working perfectly when using mode as capacity.

EDIT: GMT calculation seems to be off again - checking...

@WhimsySpoon
Copy link

I think I spoke to soon. It looks like the issue is with it not respecting irrigation_target when it's set to 0, regardless of mode, it only opens with the physical button.

When the irrigation_target is set to 0 and the valve is opened via Z2M, something is happening inside the device (a small click can be heard, but it's not the same sound as the valve opening up), it then immediately closes again. Using the physical button works fine.

I think this may be a limitation of this devices firmware which is possibly solved in the later version. The only work-around I can find is setting the irrigation_target to the largest possible value.

Either way, it's not a problem with this code as the issue is present with the current code and this release.

Apologies for the back-and-forth on this one, @drakhart, and thanks again for all of your efforts.

@drakhart
Copy link
Contributor Author

No problem, @WhimsySpoon, better be safe than sorry. Thanks for taking your time double-checking all these things. ❤️

It indeed sounds like a limitation with sh1btabb, because setting the irrigation target to zero on a7sghmms leaves the valve open until manually closed. Let me update sh1btabb description removing this mention to the zero value to avoid misleading the end user and we'll be good to merge.

@drakhart
Copy link
Contributor Author

@Koenkk we're all good, please merge when you have the time. 👍 Thanks.

@Koenkk Koenkk merged commit 2e2383c into Koenkk:master Mar 15, 2023
@Koenkk
Copy link
Owner

Koenkk commented Mar 15, 2023

Thanks!

@fedegrc
Copy link

fedegrc commented Mar 16, 2023

I have tested the _TZE200_a7sghmms several times this week with no problems. Thank @drakhart! Good job

@WhimsySpoon
Copy link

@drakhart The UK recently moved to British Summer Time, or BST which is GMT+1 and the local times are still showing as GMT, so an hour behind current.

You're not going to believe this, but changing the following back to 1970 fixes this:

const local = new Date(`2000-01-01T${time}.000${timezone}`);

I'm going to have a play with this and try and get to the bottom of it before I open a new PR.

@drakhart
Copy link
Contributor Author

drakhart commented Apr 1, 2023

@drakhart The UK recently moved to British Summer Time, or BST which is GMT+1 and the local times are still showing as GMT, so an hour behind current.

You're not going to believe this, but changing the following back to 1970 fixes this:

const local = new Date(`2000-01-01T${time}.000${timezone}`);

I'm going to have a play with this and try and get to the bottom of it before I open a new PR.

Ok, please let me know your findings and let's see if we can get this sorted out once and for all. 🤞

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