pinkywafer / Anniversaries

Anniversary Countdown Sensor for Home Assistant
MIT License
169 stars 25 forks source link

Dates off from what is set to what is in Attributes #106

Closed tetragram55 closed 2 years ago

tetragram55 commented 3 years ago

I love this add on, thank you for making it. I noticed this today, I don't know when it started but it wasn't always like this. I am using core-2021.6.4 with the latest version of Anniversaries The date set in the set up is as follows: HASS-Anniv-error-2

But what is shown in Attributes is this:

HASS-Anniv-error

bbgott commented 3 years ago

I'm having the same issue, but I am noticing it is only happening to newer entries. Birthdays or anniversaries that I had in there from before are displaying the correct date. I am running core-2021.6.5 and Anniversaries version 4.3.1

pinkywafer commented 3 years ago

Unable to reproduce.... Can you give any more info?

Grey-Lancaster commented 3 years ago

not sure what info you need. same issue. Not sure when HA changed to the dropdown box to see the dates. Did not notice it before. Timezone America/Indiana/Indianapolis units imperial/Fahrenheit

image image

Grey-Lancaster commented 3 years ago

perhaps having different sensor names? image

pinkywafer commented 3 years ago

Sensor names shouldn't affect it.... But I'm wondering if timezone could be affecting it... The sensor is based on the date, so effectively the time in the datetime object is 0:00:00. I'm wondering if this is the issue... I'll investigate.

Also, just as a check.. can you tell me if the countdown number of days is reporting correctly, ie. It's not also a day off?

Grey-Lancaster commented 3 years ago

if I ask google how many days until it matched the # of days you display

pinkywafer commented 3 years ago

Thanks. I'll look into the date... Expect it's timezone related

Grey-Lancaster commented 3 years ago

The date should not be calculated in attributes ? It should just pull/match from the input?

Grey-Lancaster commented 3 years ago

Or does it need to be calculated for the half anniversary?

pinkywafer commented 3 years ago

It's checked and converted to a datetime rather than a text (it could come from a template in the configuration.yaml) so it's most likely to be there. Ie if the date returned to home assistant is 15/7/21@0:00:00UTC, that would equate to 14/7/21@20:00 Washington

That's what I'm expecting anyway.... Leave it with me!

pinkywafer commented 3 years ago

well, so far, I'm drawing a blank.

If I add some extra debug lines would anyone who has this issue mind testing and send me back the logs please.

pinkywafer commented 3 years ago

OK, I've published a beta release with debug logging in an attempt to find out where this issue is coming from. to install it using hacs, go to your integrations. Find the Anniversaries integration. Press the menu (Three dots). Press Reinstall. You should be presented with the option to select the version to install. Turn on show beta versions. Choose version 4.4.1b1

to enable the debug logging, you will need the following in your configuration.yaml:

logger:
  default: warning
  logs:
    custom_components.anniversaries: debug

reboot home assistant and we should get some logging information

Grey-Lancaster commented 3 years ago

How long will it take for a debug file to show? I have installed 1b1 added logger: and rebooted, but I do not see anything

pinkywafer commented 3 years ago

The log entries should appear as soon as you reboot (assuming you have anniversary sensors configured) or whenever you add a new one on the integrations page. The logs should be in your main home assistant log. - on the log page you need to press load full home assistant log

Grey-Lancaster commented 3 years ago

I was looking in the aniverseries folder. I misspelled test lol

anniversaries Version: 4.4.1b1 This is a custom integration If you have any issues with this you need to open an issue here: https://github.com/pinkywafer/Anniversaries/issues

2021-07-15 16:21:40 DEBUG (MainThread) [custom_components.anniversaries.sensor] teat - config string - 2020-07-17 2021-07-15 16:21:40 DEBUG (MainThread) [custom_components.anniversaries.sensor] teat - date - 2020-07-17 00:00:00 2021-07-15 16:21:40 DEBUG (MainThread) [custom_components.anniversaries.sensor] teat - formatted date - 2020-07-17 image

pinkywafer commented 3 years ago

Ok, so I believe that the issue started when Home assistant started using native types instead of attributes just being text.

In the example @tetragram55 gave at the beginning, the date in attributes is now listed as: December 21, 1960 This (ignore that it's the wrong date for now) is a home assistant date formatted by home assistant. The date format option is configured as %Y-%m-%d which should give 1960-12-22

So I have two options:

  1. Keep the optional formatting and force the date attribute the be returned as a text Or (and I think my preferred option)
  2. Remove the configuration option for date format and let home assistant deal with the formatting and just ensure that the date is passed in a 'local' manner so that timezone issues do not give the wrong date

My reasoning for choosing 2... No-one has raised any issues regarding the lack of formatting in the date attribute, so I'm assuming that it hasn't caused any issues. Also, using the native format should actually make any templating on this attribute easier. Additionally, of the date is formatted by home assistant, it then visually matches all other dates in home assistant.

Grey-Lancaster commented 3 years ago

well I really have no idea what you just said :) All I want to do is when I expand attributes I want to see the actually date, not one off :) Again could you just not show what the thing was set for without any calculation? The # of days is correct. Thanks for working on it. Grey

bbgott commented 3 years ago

I like the sound of option 2 because it will visually match other dates in home assistant

Grey-Lancaster commented 3 years ago

Any progress on this issue? I do not want to miss my Birthday ;-)

pinkywafer commented 2 years ago

Can anyone please try the 2022.01.04 release and let me know if that solves it? - For manual install, you only need the sensor.py from the timezone-fix-test branch. To do hacs install, go to hacs and find the anniversaries integration. Click the menu (3 dots). Choose Redownload. Ensure Show beta versions is turned on and choose the 2022.01.04 release. You'll need to reboot Home Assistant

Grey-Lancaster commented 2 years ago

image I did : To do hacs install, go to hacs and find the anniversaries integration. Click the menu (3 dots). Choose Redownload. Ensure Show beta versions is turned on and choose the 2022.01.04 release. You'll need to reboot Home Assistant

pinkywafer commented 2 years ago

Sorry my bad... I used an invalid version number. I think I've fixed that now if you can redownload.

If not, revert to stable and I'll look again tomorrow

Grey-Lancaster commented 2 years ago

No it is all wrong. It did not fix previous so I made a new entry for March 13th. It still shows March 12th in attributes and the days (perhaps I should not have selected default, is off ) image

Grey-Lancaster commented 2 years ago

Yes, I selected count up and I should have not checked anything

pinkywafer commented 2 years ago

So still just date that's off?

Grey-Lancaster commented 2 years ago

yes, image

pinkywafer commented 2 years ago

can you tell me if the sensor is updating at midnight (as it should) or at some other time?

Grey-Lancaster commented 2 years ago

Midnight

pinkywafer commented 2 years ago

Thanks - it looks like a frontend issue - I think I'm getting somewhere now! seems unrelated to #110

pinkywafer commented 2 years ago

ok. The date is correct (internally): the template: {{state_attr("sensorname","date")}} returns the correct date. The problem is that the UI recognises the attribute as a date, assumes it's UTC and converts it in the UI only to the date to suit the browser settings bitmoji This is NOT what is intended. I'll look into a way to stop this or a workaround. In the meantime, anything else that reads the attribute should get the correct value!

pinkywafer commented 2 years ago

can you try the 2022.01.07 beta please? I've forced the date into the "default" timezone. Hopefully this will cure the issue, but we've lost the option to format the date - something that I think we'll just have to live with as this is how the UI now works

Grey-Lancaster commented 2 years ago

I also created a new one and it is the same, one day off

image

image

image

pinkywafer commented 2 years ago

Ok, let's try with the full datetime object - can you try 2022.01.07-2 please

Grey-Lancaster commented 2 years ago

dash 2 is not showing up for me yet

pinkywafer commented 2 years ago

on hacs, find anniversaries - press 3 dots - update information. This saves you waiting for hacs to update!

Grey-Lancaster commented 2 years ago

well that is not working at all dash 2 image

pinkywafer commented 2 years ago

OK - Home Assistant doesn't like dash in release numbers.... try 2022.01.07r2 instead!

Grey-Lancaster commented 2 years ago

working on it figured I best do a full backup first :-)

Grey-Lancaster commented 2 years ago

sorry, no change on old entries or new ones image

pinkywafer commented 2 years ago

My bad... in my haste I released from the wrong branch!

can you try r3

Grey-Lancaster commented 2 years ago

That works, shows 12:00am YEA :-) image

pinkywafer commented 2 years ago

bitmoji Thanks for your help. I've had enough for tonight! I'll sort out removing the unneeded config options etc and updating docs then I'll make a new release.

Grey-Lancaster commented 2 years ago

I figured you must not be on my side of the pond. Sleep well and thank you !

pinkywafer commented 2 years ago

closed by #114