Author Topic: How to get Attributes back from hubitat  (Read 221 times)

0 Members and 1 Guest are viewing this topic.

Tom_G_2010

  • Jr. Member
  • **
  • Posts: 18
  • Karma: 2
    • View Profile
How to get Attributes back from hubitat
« on: January 24, 2025, 12:18:07 PM »
Hi, after several years away from Vox Commando I'm back at it. I have switch, color, hue, and level controls all working between VC and my Hubitat. I'll have a few questions about how to streamline things later but for now I'm trying to wrap my head around reading things back from Hubitat.

If I use my browser to send http://192.168.123.123/apps/api/543/devices/123/attribute/colorName?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx to Hubitat. Hubitat returns  {"id":"123","attribute":"colorName","value":"Red"}

What I want to do is send that to Hubitat and based on response from Hubitat have VC speak the color using TTS.

Will Scrape pickup hubitat's response or do I need to use Get?  I've tried a few different things but can't figure out how to pick up that response and parse the color from it.  I looked at the Wiki and several forum posts, but I haven't been able to figure it out yet.

Any help would be greatly appreciated.

Thanks!
Tom G.\.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7720
  • Karma: 116
    • View Profile
    • VoxCommando
Re: How to get Attributes back from hubitat
« Reply #1 on: January 24, 2025, 05:31:16 PM »
Hi Tom.

Just scrape will put that string with the colour in to the {LastResult} variable.  You could use an action like OSD.Show {LastResult} and it would show you {"id":"123","attribute":"colorName","value":"Red"}

But you want to isolate the colour from the rest of that info so you need to use result.regex to search the string for a matching pattern.

I've created a command that does this for you to get the "value".  It will work for anything that returns a value string. Note that if you are asking for a number like dim level then the pattern will be a bit different because the json won't have quotes around the value.  You can paste this xml into your editor to get an idea of how the macro should work.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.5.0.2-->
<command id="1329" name="get device info" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://192.168.123.123/apps/api/543/devices/123/attribute/colorName?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>"value":"(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{Match.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>

Tom_G_2010

  • Jr. Member
  • **
  • Posts: 18
  • Karma: 2
    • View Profile
Re: How to get Attributes back from hubitat
« Reply #2 on: January 25, 2025, 12:15:07 PM »
I built the following and the OSD shows the sting coming back with the color at the end of it, but the TTS is speaking the variable name "Match One" instead of the variable result "Red."

Code: [Select]
            <command id="171" name="What Color" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
                <action>
                    <cmdType>Scrape</cmdType>
                    <params>
                        <param>http://192.168.123.123/apps/api/543/devices/{1}/attribute/colorName?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</param>
                    </params>
                    <cmdRepeat>1</cmdRepeat>
                </action>
                <action>
                    <cmdType>Results.RegEx</cmdType>
                    <params>
                        <param>"value":"(.*?)"</param>
                    </params>
                    <cmdRepeat>1</cmdRepeat>
                </action>
                <action>
                    <cmdType>TTSMS.Speak</cmdType>
                    <params>
                        <param>{Match.1}</param>
                    </params>
                    <cmdRepeat>1</cmdRepeat>
                </action>
                <action>
                    <cmdType>OSD.ShowText</cmdType>
                    <params>
                        <param>{LastResult}</param>
                    </params>
                    <cmdRepeat>1</cmdRepeat>
                </action>
                <phrase>What Color is</phrase>
                <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">Hubitat Device List.xml</payloadFromXML>
            </command>

I tested the regex syntax in the Expression Helper, and it returns 1:"value":"Red"

I did a couple tests with fixed device IDs to be sure it wasn't my payload table.
All of them returned a string with either the lights color or null for none RGB bulbs.
But the TTS always comes back "match one".

Did I botch something in my setup?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7720
  • Karma: 116
    • View Profile
    • VoxCommando
Re: How to get Attributes back from hubitat
« Reply #3 on: January 25, 2025, 12:37:02 PM »
It looks correct to me.  I would need to see a log to help you further.

Tom_G_2010

  • Jr. Member
  • **
  • Posts: 18
  • Karma: 2
    • View Profile
Re: How to get Attributes back from hubitat
« Reply #4 on: January 25, 2025, 07:40:57 PM »
Here's the log from one execution of the command:

Code: [Select]
1/25/2025 6:22:34 PM 207 Something was recognized
1/25/2025 6:22:34 PM 207 Rulename: root # Semantics: 3
1/25/2025 6:22:34 PM 207 Group: Device Montor Speech: Maggie What Color is Ambient Lighting
1/25/2025 6:22:34 PM 208 semanticID: 171
1/25/2025 6:22:34 PM 208 kvp: prefix | Maggie
1/25/2025 6:22:34 PM 208 kvp: command | 171
1/25/2025 6:22:34 PM 208 kvp: payload1 | <171:Ambient Lighting>710
1/25/2025 6:22:34 PM 208 no regex match found
1/25/2025 6:22:34 PM 208 id from payload value: 171
1/25/2025 6:22:34 PM 210 semanticID: 171
1/25/2025 6:22:34 PM 210 kvp: prefix | Maggie
1/25/2025 6:22:34 PM 210 kvp: command | 171
1/25/2025 6:22:34 PM 210 kvp: payload1 | <171:Ambient Lighting>710
1/25/2025 6:22:34 PM 210 no regex match found
1/25/2025 6:22:34 PM 210 id from payload value: 171
1/25/2025 6:22:34 PM 210 alternate:Maggie What Color is Ambient Lighting
1/25/2025 6:22:34 PM 220 A prefix is required to execute this command.
1/25/2025 6:22:34 PM 246 addHistoryItem [vcevent] VC.Prefix.End

1/25/2025 6:22:34 PM 250 doCommand:What Color
1/25/2025 6:22:34 PM 250 Action claims to be threadsafe.
1/25/2025 6:22:34 PM 250 action repeat set to: 1
1/25/2025 6:22:34 PM 250 Action:  Scrape
1/25/2025 6:22:34 PM 250 Param1:http://192.168.123.123/apps/api/543/devices/710/attribute/colorName?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1/25/2025 6:22:34 PM 250 addHistoryItem [action] Scrape:http://192.168.123.123/apps/api/543/devices/710/attribute/colorName?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

1/25/2025 6:22:34 PM 300 Action RESULT:
1/25/2025 6:22:34 PM 300 Action is NOT threadsafe: Results.RegEx
1/25/2025 6:22:34 PM 300 action repeat set to: 1
1/25/2025 6:22:34 PM 300 Action:  Results.RegEx
1/25/2025 6:22:34 PM 300 Param1:"value":"(.*?)"
1/25/2025 6:22:34 PM 300 addHistoryItem [action] Results.RegEx:"value":"(.*?)"

1/25/2025 6:22:34 PM 308 addHistoryItem [error] Results.RegExUnexpected error:
System.NullReferenceException: Object reference not set to an instance of an object.
   at VoxCommando.ResultsVars.RegExMyResults(String[] parsedParams, Boolean useSingleLine)
   at eval_g.eval_ᜃ(macroElement A_0, List`1 A_1, Int32 A_2)
   at eval_g.eval_ᜂ(macroElement A_0, List`1 A_1, Int32 A_2)
1/25/2025 6:22:34 PM 314 Unexpected error in action: Results.RegEx
System.NullReferenceException: Object reference not set to an instance of an object.
   at VoxCommando.ResultsVars.RegExMyResults(String[] parsedParams, Boolean useSingleLine)
   at eval_g.eval_ᜃ(macroElement A_0, List`1 A_1, Int32 A_2)
   at eval_g.eval_ᜂ(macroElement A_0, List`1 A_1, Int32 A_2)
1/25/2025 6:22:34 PM 314 Action claims to be threadsafe.
1/25/2025 6:22:34 PM 314 action repeat set to: 1
1/25/2025 6:22:34 PM 314 Action:  TTSMS.Speak
1/25/2025 6:22:34 PM 314 error replacing variables: {Match.1}
1/25/2025 6:22:34 PM 314 Param1:{Match.1}
1/25/2025 6:22:34 PM 314 addHistoryItem [action] TTSMS.Speak:{Match.1}

1/25/2025 6:22:34 PM 319 Action from plugin: C:\VOX COMMANDO\Plugins\TTSMS\TTSMS.dll
1/25/2025 6:22:34 PM 320 Action INFO: speaking (asynchronous): {Match.1}
1/25/2025 6:22:34 PM 324 Action is NOT threadsafe: OSD.ShowText
1/25/2025 6:22:34 PM 324 action repeat set to: 1
1/25/2025 6:22:34 PM 324 Action:  OSD.ShowText
1/25/2025 6:22:34 PM 325 Param1:{"id":"710","attribute":"colorName","value":"Red"}
1/25/2025 6:22:34 PM 325 addHistoryItem [action] OSD.ShowText:{"id":"710","attribute":"colorName","value":"Red"}

1/25/2025 6:22:34 PM 355 Action INFO: OK
1/25/2025 6:22:34 PM 356 addHistoryItem [vcevent] tts.start

1/25/2025 6:22:36 PM 4 addHistoryItem [vcevent] tts.end

1/25/2025 6:22:37 PM 852 addHistoryItem [vcevent] VC.NotRecognized

1/25/2025 6:22:38 PM 351 guessed text:Is The ?? (Device Montor)
1/25/2025 6:22:39 PM 471 addHistoryItem [vcevent] VC.NotRecognized

I see what looks like regex related error in the middle of the log but I'm not sure how to interpret them.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7720
  • Karma: 116
    • View Profile
    • VoxCommando
Re: How to get Attributes back from hubitat
« Reply #5 on: January 25, 2025, 08:20:17 PM »
Are you running these actions with the correct access token and then replacing them in the log?  Or did you forget to put the correct URL with the correct access token back into the action fields?

Tom_G_2010

  • Jr. Member
  • **
  • Posts: 18
  • Karma: 2
    • View Profile
Re: How to get Attributes back from hubitat
« Reply #6 on: January 25, 2025, 08:34:10 PM »
What's running in Vox Commando and showing in my actual logs is the correct access token.

When posting I mask my access tokens.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7720
  • Karma: 116
    • View Profile
    • VoxCommando
Re: How to get Attributes back from hubitat
« Reply #7 on: January 25, 2025, 09:17:18 PM »
I'm very confused by the error in the log. Any chance we could screen share and look at it together?

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7720
  • Karma: 116
    • View Profile
    • VoxCommando
Re: How to get Attributes back from hubitat
« Reply #8 on: January 25, 2025, 09:23:07 PM »
If so, send me a private message. I should have some time tomorrow.

Tom_G_2010

  • Jr. Member
  • **
  • Posts: 18
  • Karma: 2
    • View Profile
Re: How to get Attributes back from hubitat
« Reply #9 on: January 25, 2025, 10:14:45 PM »
PM Sent, THANKS!

Tom_G_2010

  • Jr. Member
  • **
  • Posts: 18
  • Karma: 2
    • View Profile
Re: How to get Attributes back from hubitat
« Reply #10 on: January 27, 2025, 07:36:12 AM »
@jitterjames

I thought I'd come back here and post a Thank You for your assistance yesterday in trouble shooting this issue and post the solution in case others hit this issue.

First, THANK YOU!  Your willingness to work on this with me is greatly appreciated!!!

Second, I was going to type up what you did but I'm not sure I got it right because yesterday evening Windows did an update, crashed my pc and I had to run recovery to get the machine to run again.  After completing the recovery, the bug was back but I can't replicate the fix so I must not have correctly understood what you did.

If you don't mind, could you post what you did to clear the bug.

Double Thanks!!!
Tom G.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7720
  • Karma: 116
    • View Profile
    • VoxCommando
Re: How to get Attributes back from hubitat
« Reply #11 on: January 27, 2025, 09:28:22 AM »
You are welcome.

It would not surprise me if a system restore were responsible for the problem in the first place.

Anyway the solution is as follows.

Open options, then go to the "variables" tab.
uncheck "save and restore variables automatically"
restart VC.

If you use this feature you can turn it back on again after restarting VC.