Comments (4)
👋 Hi! New to OpenSprinkler, the HACS integration, and this Lovelace card...
Welcome! I hope it hasn't been a frustrating experience so far.
At the moment I'm not yet comfortable with how the automatic weather handling algorithms might interact with new seeds in my garden, so I'm managing weather manually with the OpenSprinkler rain delay functionality.
I want to propose the idea of showing the rain delay status on the top-level card while active... similar to the brief banner across the top that you see on the OpenSprinkler home page or mobile app.
That's a great idea! Not quite the same, but you could show the rain delay with extra_entities
:
type: custom:opensprinkler-card
extra_entities:
- binary_sensor.opensprinkler_rain_delay_active
- sensor.opensprinkler_rain_delay_stop_time |
I've got a prototype that comes out looking like this... but before I pitch that as a PR, wanted to get your reaction as to whether that's a direction you would be interested in going or not:
Thoughts?
Basically looking to extend the high-level view of what's happening with my OpenSprinkler to also include "nothing... because there's a rain delay."
This looks amazing! My only nitpick would be to change the date to a relative time (e.g. 70hr, or 30min, or 5s). That will take a lot more code to implement though, so I'm good with just date + time as a first pass.
I'm interested in how to actually update the rain delay from Home Assistant as well, but need to dig into whether that's exposed by the API and integration or not. If so, perhaps it can be exposed through the card similar to the manual station time with the
input_number
support.
You should be able to find the rain delay through the Rain Delay Stop Time entity. The card collects a list of entities belonging to the OpenSprinkler device, so if you assume the entity id still has "rain_delay_stop_time" (hopefully the user didn't change it), then you can filter for it.
from opensprinkler-card.
Alrighty, I've got everything working to dynamically filter for the ...rain_delay_active
and ...rain_delay_stop_time
sensors, check the state of the former and then display time based on the latter. 👍
if you assume the entity id still has "rain_delay_stop_time" (hopefully the user didn't change it), then you can filter for it.
Yes, good point here... I'll add it to the README
note about requirements for named entities in the PR.
My only nitpick would be to change the date to a relative time (e.g. 70hr, or 30min, or 5s).
I like that! So, further questions for you, with apologies that I'm a dangerous newbie at best in JavaScript 😄:
I looked briefly at implementing this, and think there are a few possible paths depending on your philosophy about dependencies... what would you recommend/prefer as an approach?
In general I will need to:
- Get the relative time between "now" and the timestamp from the
rain_delay_stop_time
sensor. - Select an appropriate relative unit based on the scale... 5 minutes, 15 hours, 2 days, etc.
- Format to a text string
A few options:
- Follow Home Assistant frontend's lead, and use
@formatjs/intl-utils
plusIntl.RelativeTimeFormat
/Intl.NumberFormat
.intl-utils
offersselectUnit
which does timestamp diffing plus relative unit selection, which are then passed to one of the two formatting options depending on whether we prefer to say "Rain delay endsin 14 hours
" or "Rain delay endstomorrow
" versus "Rain delay for14 hours
". (The former does localized handling of relative time in future or past tense... the latter just does the number plus plural (or not) unit).- BUT:
@formatjs/intl-utils
is deprecated. Not sure your stance on taking a new dependency on it, whether or not HA itself does.
- Use a current datetime library like
luxon
to do the work.luxon
offersDateTime.toRelative
which combines the diff and relative formatting.- Only formatting option there would be "Rain delay ends
in 14 hours
" style - I don't see a trivial path to the number-only format ("Rain delay for14 hours
"), thoughDuration.toHuman
is similar with caveats.
- Only formatting option there would be "Rain delay ends
- Write something custom to avoid any new dependencies, at the cost of rewriting some kind of unit selection code. Formatting would still be easiest to do by consuming the localization of
Intl.NumberFormat
.
Any preferences or recommendations there? Left to my own devices I would probably try (2) with luxon
, and create a string like "Rain delay ends in 14 hours
".
My other question on any of the above is whether it's safe to rely on browser support for Intl.xxFormat
(which all three would likely be using), or if we need to do any of the polyfill work to handle older browsers. What's normal for a custom-card?
Thanks for your thoughts & time! 😁
from opensprinkler-card.
Quick update: In further testing, I found a bug in the underlying python library that powers the HACS integration. The Rain Delay Stop Time is not actually corrected for OpenSprinkler's time zone settings, resulting in a local timestamp being incorrectly labeled as UTC in home assistant, and badness ensuing when computing a relative time. I missed this when doing simple date formatting since I wasn't pretty printing the timezone...
Working on fixing it quick, then will circle back to this PR since the relative time math really depends on valid underlying timestamps 😄
from opensprinkler-card.
OK, got the changes to the upstream python library used in the integration merged, so correct timestamp data will be flowing for the rain delay stop time.
I researched the relative time a bit more, and found that custom-card-helpers
actually already did the legwork, and exposes relativeTime
exactly mirroring the HA frontend implementation.
Let's use that. Details in the PR #17:
- Need to update
custom-card-helpers
to 1.9.0 to get the latest functional version - Need to update
home-assistant-js-websocket
to^6.0.1
to be compatible withcustom-card-helpers
in order to shareConnection
,UnsubscribeFunc
, etc.
from opensprinkler-card.
Related Issues (17)
- Remove disabled entities HOT 2
- Weird quirk when an entity is disabled HOT 9
- OpenSprinkler Enable in extra_entities HOT 2
- wrong place for this but i cant figure out.. HOT 7
- Master stations shall not be controllable HOT 1
- Installed OS card from HACS. Can't find the card to use it. HOT 2
- Manually start program if disabled
- No drop down available to choose device HOT 3
- input_number not working HOT 2
- How to put card Title?? HOT 1
- Duration timer bar displays incorrect time when station has started HOT 4
- OpenSprinkler Card Totally Messed up
- Station Icons HOT 2
- Supporting additional parameters of numberbox-card HOT 3
- Feature request: remove the 3 dots showing history HOT 2
- Duplicate station names not handled correctly HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opensprinkler-card.