Author Topic: Simple arithmetic calculations  (Read 3388 times)

0 Members and 1 Guest are viewing this topic.

Tougharms

  • $upporter
  • Jr. Member
  • *****
  • Posts: 10
  • Karma: 0
    • View Profile
Simple arithmetic calculations
« on: July 17, 2014, 06:24:31 PM »
I am using a Vera Lite Home automation that has a 3-way motion, light and temperature sensor connected.

I know how to get the temperature from the sensor and how to make Vox read it out to me, but unfortunately for me, the sensor only reports Fahrenheit, while being in the UK, everything else I have uses Celsius. There is no option on the sensor to change the output to C.

I know the calculation to convert F to C, but how on earth do I get Vox to do the calculation?
I stood in the shadow of the moon!

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Simple arithmetic calculations
« Reply #1 on: July 17, 2014, 06:42:38 PM »
Python plugin for the win. See wiki: http://voxcommando.com/mediawiki/index.php?title=Python#Returning_a_Result

One action is all that is needed once the plugin is enabled. Nothing complicated.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.0.0.0-->
<command id="306" name="Fahrenheit to Celsius" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecString</cmdType>
    <params>
      <param>result=(tempF-32)*5/9</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{LastResult} Celsius</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>

My tempF in the above is just a placeholder. You'd presumably get the temp using a Vera.Get action, and replace my tempF with {LastResult}.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Tougharms

  • $upporter
  • Jr. Member
  • *****
  • Posts: 10
  • Karma: 0
    • View Profile
Re: Simple arithmetic calculations
« Reply #2 on: July 17, 2014, 08:32:56 PM »
Thanks.

Very simple indeed, when you know  ;D

I thought it would involve python. I searched the forum and the wiki for mathematics, arithmetic, calculation and other terms I could think of and found nothing. It didn't occur to me to search for 'result'

So to make sure I understand correctly, if I call python to do any calculation with PY.ExecStrin  and use "result=" then Vox's {LastResult} will always pick it up. Is that correct?

p.s. it's half past midnight and 78 F/ 25.5 C here
I stood in the shadow of the moon!

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: Simple arithmetic calculations
« Reply #3 on: July 18, 2014, 12:10:04 AM »
Hi Tougharms, this is one of the results which I get when I type "math" in the forum seach field  ;)

http://voxcommando.com/forum/index.php?topic=1005.0

and yes you are correct  :)
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Simple arithmetic calculations
« Reply #4 on: July 18, 2014, 08:20:40 AM »
Some people may not realise that the search on the forum works in an specific way.  If you are already reading a thread and you type something into the search box, it will only search the thread you are already on. To search the whole forum you must go back to the main forum page and then search.

Personally I prefer to search using google because it allows for different spellings etc.

The custom search on the wiki is the most useful or in google directly, type what you are looking for and then add this to you search terms

Code: [Select]
Site: voxcommando.com

Tougharms

  • $upporter
  • Jr. Member
  • *****
  • Posts: 10
  • Karma: 0
    • View Profile
Re: Simple arithmetic calculations
« Reply #5 on: July 18, 2014, 06:23:41 PM »
I started my search on Google. Then I went to the forum home page. I went through 9 pages of different subjects in the 'Help with Voxcommando' branch of the forum and I got nothing for the search examples I gave.

Also we have a problem with different languages, Canadian (American) English is different to UK English. For example, with all respect to Kalle, in the UK we don't do math, we do maths (short for mathematics, you see). It would never have occurred to me to search for 'math', it is just not a word we use in the UK.

Anyway, nime5ter solved the problem for me and pointed me in the correct direction, now I have the starting point and I know where to look in the future and I am grateful for the assistance. I was already using Python to control a Tivo box, and I guessed the the calculations would have to be done in Python, I just could not figure out how to pass the information each way. I can see now that the actions are so obvious to people familiar with it that it is hardly ever documented.

Thanks to all for your time reading my posts and for all your help.

Now I'm going to have a beer and calculate something.

Cheers to you all!
I stood in the shadow of the moon!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Simple arithmetic calculations
« Reply #6 on: July 18, 2014, 06:49:29 PM »
Also we have a problem with different languages, Canadian (American) English is different to UK English. For example, with all respect to Kalle, in the UK we don't do math, we do maths (short for mathematics, you see). It would never have occurred to me to search for 'math', it is just not a word we use in the UK.


This is why I suggest using Google instead of the search on the forum.  I'm not telling you this to say that you did it wrong, but you help you for next time you are looking for something.  Google's algorithms don't mind a silly little thing like an 's' on the end of a word.

Going through forum posts systematically isn't going to work since there are about a bazillion different things you can do with VoxCommando.  You need to be able to search.

Tougharms

  • $upporter
  • Jr. Member
  • *****
  • Posts: 10
  • Karma: 0
    • View Profile
Re: Simple arithmetic calculations
« Reply #7 on: July 18, 2014, 07:23:23 PM »
Would you believe that I actually read the first one, but couldn't figure out how to get 'result' back to Vox.  :bonk

This is what I meant when I referred to an action being so obvious to anyone familiar with it that it is not documented. {LastResult} was not mentioned.

I guess I missed the second, but that was the one that Nime5ter pointed me at.

I am not complaining because I love using the program and learning to do new things. So far I have Vox controlling a Tivo by Python socket commands, a TV and a Blu-Ray player using Itach Flex, a Vera Lite, not to mention XBMC and also VLC via EventGhost. I can normally find what I need on Google and the forum but this one beat me.

p.s. can I get the supporter logo added to my account? I paid for V1, V2 and VW Pro
I stood in the shadow of the moon!

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: Simple arithmetic calculations
« Reply #8 on: July 19, 2014, 04:43:13 AM »
Sorry for the misunderstanding  :bonk  It looks like that I use the search a bit different from others (that is one point why Naomi and James gave me the name "special'K"  :biglaugh ). I search mostly only a part from a whole word (if I don't know what exactly I search for or how it is written correctly), so I think I had luck at this point.
***********  get excited and make things  **********