Shortened Sunrise/Sunset Time?
Posted:
Sat Aug 08, 2020 9:41 am
by sumocomputers
Using the Astronomy device, I wanted to display Sunrise/Sunset Time on a Control Page, and currently it shows something like:
2020-08-08 07:42 PM
I really only need 7:42 PM, or even just 7:42, as in our area, Sunrise is assumed AM, Sunset PM.
I looked at FW Plugin configuration options, and couldn't find a way to do it easily, though I did see the 12 hour option without AM/PM.
I guess I could write these to a variable, and somehow strip off the leading date & leading zero, but was wondering if there is another way I am missing, or perhaps this might be a feature request?
Thanks,
Chris
Re: Shortened Sunrise/Sunset Time?
Posted:
Sat Aug 08, 2020 10:29 am
by DaveL17
Hi Chris - I've uploaded v1.0.02 of the plugin which includes two new states sunRiseShort and sunSetShort. Hopefully, those will work for you.
Dave
Re: Shortened Sunrise/Sunset Time?
Posted:
Sat Aug 08, 2020 10:50 am
by sumocomputers
It works awesome, thank you.
I still need to figure out a way to strip off the leading zero from time (on FW as well as the generic Indigo time that I use as a clock).
I think there was a thread on how to do this with a simple Python script, but for the life of me, I cannot find it.
Re: Shortened Sunrise/Sunset Time?
Posted:
Sat Aug 08, 2020 11:48 am
by DaveL17
It depends on what you're working with. In this instance, the plugin value is a string (and if you're working with an Indigo variable, that's a string as well).
A very simple example of stripping the leading zero from a string is:
- Code: Select all
t = [string source of value]
new_t = t.lstrip('0')
Re: Shortened Sunrise/Sunset Time?
Posted:
Sat Aug 08, 2020 1:07 pm
by sumocomputers
So I think this script should work to strip the 0 from the Sunrise/Sunset values and write it to a variable (I borrowed some of it from an existing working script, so I'm sure there is a cleaner way).
But how do I find the correct states name for Sunrise Short or Sunrise Long?
- Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
t = (indigo.devices[663603508].states['sunrise_time_short']) #FW Astronomy Device
new_t = t.lstrip('0')
indigo.variable.updateValue(555900233, format(new_t)) #New Stripped Sunrise Variable
Re: Shortened Sunrise/Sunset Time?
Posted:
Sat Aug 08, 2020 2:06 pm
by sumocomputers
I dug into the code on Git and found them. This ended up working in case anyone else (or my future self when I forget) finds it:
- Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
t = (indigo.devices[663603508].states['sunriseTimeShort']) #FW Astronomy Device
new_t = t.lstrip('0')
indigo.variable.updateValue(555900233, format(new_t)) #New Stripped Sunrise Variable
- Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
t = (indigo.devices[663603508].states['sunsetTimeShort']) #FW Astronomy Device
new_t = t.lstrip('0')
indigo.variable.updateValue(489151405, format(new_t)) #New Stripped Sunset Variable
Re: Shortened Sunrise/Sunset Time?
Posted:
Thu Aug 13, 2020 6:02 am
by howartp
Depending if astronomy sunrise/set is different to normal, the Clock Display plugin supports sunrise/set and may help you tidy this up?
Sent from my iPhone using Tapatalk Pro
Re: Shortened Sunrise/Sunset Time?
Posted:
Mon Aug 17, 2020 10:10 am
by sumocomputers
howartp wrote:Depending if astronomy sunrise/set is different to normal, the Clock Display plugin supports sunrise/set and may help you tidy this up?
Sent from my iPhone using Tapatalk Pro
Even though I have everything working, I will check out the Clock plugin!