jcgoette / baby_buddy_homeassistant

This custom integration provides sensors for Baby Buddy API endpoints.
MIT License
64 stars 30 forks source link

Date/Time could not be in the future #59

Closed kazzaw closed 2 years ago

kazzaw commented 2 years ago

Attempting to run a script through home assistant to log a diaper change with the press of a button. This has worked well up until now, for some reason it is no longer working. Home assistant gives the following log error

Could not create changes. error: {'time': ['Date/time can not be in the future.']}

When calling the diaper change service manually the same error appears.

Logging normally through the web page works fine.

jcgoette commented 2 years ago

I'm not sure this is an issue with the HA integration. Have you seen https://github.com/babybuddy/babybuddy/discussions/300#discussioncomment-2311948?

kazzaw commented 2 years ago

I had a look at that, I'm not using iOS so I can't see what the 'shortcuts' are.

I have a widget set through home assistant app (Android), for a wet or dirty diaper. When pressed, this runs a script which 1) Call Service - Baby Buddy: Add diaper changer Target - Baby Change time - Empty (which should use now) Diaper Type -Solid

2) Call Service - Grocy: Consume product from stock

When HA tries to make an entry into Baby Buddy, it gives the error mentioned above. If I try to manually (through developer tools) attempt to call the add diaper change service with no time, it also triggers the same error. If I do the above but put the time back ~30 minutes, it works fine.

When entering through Baby buddy direct, there is no issue. This has been working for ~1 week (since I configured it) without issue however has recently just stopped working.

Log times in Home Assistant are correct, as are the entries in Baby Buddy when I log them manually.

Perhaps there is a small time difference in the 2 devices which is causing the issue?

jcgoette commented 2 years ago

Do you mind reading through this exchange?

"Perhaps there is a small time difference in the 2 devices which is causing the issue?" I think this is probably the case. I looked to see if BB had been updated to default to now() if no end provided, but that is not the case. Maybe @cdubz could give that some thought?

five2seven commented 2 years ago

This just started happening to me about 2 hours ago. All changes from this morning were logged normally using HA buttons but now pressing the buttons gives me that same error.

five2seven commented 2 years ago

My fix for the last 2 weeks has been to create REST commands in HA for my diaper logging buttons instead of calling this service. The time is set to now-1sec and that works perfectly. I don't want to create more REST entries for every single thing I log though so I'm hoping there's a fix to get this integration back up and running.

jcgoette commented 2 years ago

@five2seven what's stopping you from using the same time offset with the integration?

kazzaw commented 2 years ago

@five2seven how do you do this? I might have to take this route, I can't seem to figure out how to put a delay in the time when calling the service

jcgoette commented 2 years ago

Should be fixed in BB v1.11.0 via https://github.com/babybuddy/babybuddy/pull/438.

bd55b1f75a2b664386a8eb018b85df99d701e916 allows the BB update to work, but fails back to now() if user hasn't upgraded BB yet.