Python Conversion?

Posted on
Mon Jul 02, 2018 12:35 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Python Conversion?

Maybe there's a Python version of this?

Code: Select all
tell application "IndigoServer"
   set theText to value of variable "WUForecast"
   
   set swapOut to "Snow Showers" as string
   set swapIn to "Snow" as string
   
   if the theText contains the swapOut then
      set AppleScript's text item delimiters to the swapOut
      set the text_item_list to every text item of theText
      set AppleScript's text item delimiters to the swapIn
      set the theText to the text_item_list as string
      set AppleScript's text item delimiters to ""
   end if
   set the value of variable "WUForecast" to theText
end tell


Thanks,

Carl

Posted on
Mon Jul 02, 2018 12:54 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python Conversion?

https://www.tutorialspoint.com/python/s ... eplace.htm

Code: Select all
forecast = indigo.variables[12345678].value    # "WUForecast"
forecast.replace("Snow Showers", "Snow")
indigo.variable.updateValue(12345678, forecast)


More or less.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jul 02, 2018 2:49 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Conversion?

Python is so much better at string manipulation... :)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jul 02, 2018 3:07 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Python Conversion?

jay (support) wrote:
Python is so much better at string manipulation... :)

Python is so much better a pretty much anything and everything with the slight exception of a few integration tasks with macOS.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Mon Jul 02, 2018 3:56 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python Conversion?

Perfect, thanks.

Carl

Posted on
Mon Jul 02, 2018 3:59 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python Conversion?

With a test for the string, saves doing the update if not needed:
Code: Select all
forecast = indigo.variables[12345678].value    # "WUForecast"
if "Snow Showers" in forecast:
    forecast.replace("Snow Showers", "Snow")
    indigo.variable.updateValue(12345678, forecast)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jul 02, 2018 4:43 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python Conversion?

If I could bug you for another...

Need to insert a device state into a variable as an integer. Been using Applescripts to trigger on variable
changes but they’re pretty unreliable.

Thanks,

Carl

Posted on
Mon Jul 02, 2018 4:47 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python Conversion?

ckeyes888 wrote:
Need to insert a device state into a variable as an integer. Been using Applescripts to trigger on variable
changes but they’re pretty unreliable.


You shouldn't need Python for that. Can't you use the Indigo "Variable Actions -> Insert Device State into Variable" action?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jul 02, 2018 4:55 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python Conversion?

Yes, but the Weather Plus device state I’m using inserts the state as 65.0, I need it without the decimal...65.

Thanks,

Carl

Posted on
Mon Jul 02, 2018 4:57 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Python Conversion?

Carl, if you look at the Device Extensions plugin you can reformat that number however you want and then store that if you desire or just leave it where it is because it's a device state that can be triggered upon or whatever you need to do. Just use a conversion extension to either transform your number and trim the decimals or you can use it as a string and cut off the last two characters, either way it sounds like it'll take care of what you need to do.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Mon Jul 02, 2018 5:00 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Python Conversion?

Another plugin, Super Conditions also lets you read in data from wherever in Indigo and stash it into a variable if you want, it does some conversion but not as much as Device Extensions does.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Mon Jul 02, 2018 5:14 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python Conversion?

Thanks a bunch but am unsure of what the settings should be to remove the .0 and let it be as many as 3
integers. e.g. 100.

Edit: Seems regardless of what settings I enter I’m not seeing any states change in the Device Extentions device.
I assume I would trigger from a change in the DE state to insert to a variable?

Carl
Attachments
530AEB4E-2788-428F-9050-E5BD1CFD089B.jpeg
530AEB4E-2788-428F-9050-E5BD1CFD089B.jpeg (278.84 KiB) Viewed 2488 times

Posted on
Mon Jul 02, 2018 5:41 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Conversion?

ckeyes888 wrote:
Need to insert a device state into a variable as an integer. Been using Applescripts to trigger on variable
changes but they’re pretty unreliable.


Code: Select all
state_value_as_float = float(indigo.devices[DEVICEID].states[STATEID])
indigo.variable.updateValue(VARID, value=str(int(state_value_as_float)))


Should be pretty close.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jul 02, 2018 5:45 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python Conversion?

Thanks. I assume the StateID is a number?

Thanks,

Carl

Posted on
Mon Jul 02, 2018 5:53 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Conversion?

ckeyes888 wrote:
Thanks. I assume the StateID is a number?


No, it's the key/id of the state. In the device state list, it shows the custom state IDs (which is an alphanumeric string):

state_list.png
state_list.png (51.37 KiB) Viewed 2429 times

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 7 guests

cron