I'm sure someone better at HS scripting that I can offer suggestions on how to improve this, but this is the code I used to correct the importing problem I seem to be having between HS3 and Alexa.
I have some devices with possessives in the name. "Bill's Vanity" for example. Alexa often seems to get things wrong with names like that. So I've made it habit to use the 'Voice Command' field on devices to remove the apostrophe. So "Bill's Vanity" becomes just "Bills Vanity" and all is well.
I recently had some trouble with the Alexa-HS bridge and tried disabling the skill. This was a bad idea as the skill I'd been using was "an old one" and couldn't be re-enabled. When I tried using the new skill the devices all came in with the locations and name concatenated. What previously got imported as "Coffee Bar Lights" from the "1st floor" "Coffee Bar" now showed up in Alexa as "1st floor Coffee Bar Coffee Bar Lights" and voice commands to control just "Coffee Bar Lights" would fail.
So, something's going wrong with the importing. Yeah, that's not a great excuse when the wife starts complaining about why Alexa is broken.
I noticed that the error only happened on devices that DIDN'T have a Voice Command string entered.
This is my end-run around that problem.
I used a browser hack to delete only the devices with "HomeSeer" in the name from Alexa. From: https://lefkowitz.me/bulk-delete-sma...es-from-alexa/ and edited to use "HomeSeer" instead.
From a browser on the https://alexa.amazon.com/spa/index.html#appliances page I used this script in an F12 console window:
This removed all of the HomeSeer devices. Which is better than using the only other option of removing all devices, as doing so could cause a cascade of other problems if you have other skills connected.
Once the devices were gone from Alexa, I ran this code as manual script in HS3:
This marches through all of my HS3 devices and checks if they're voice enabled. If so, it checks to see if the voice command is empty. If so, it copies the device name into that field.
Once that was done I used the command "Alexa, discover devices" to re-import them.
This has solved my problem. I still question why the devices got imported that way. I have no idea if this is an Alexa problem or a Homeseer problem. Alexa does show the devices with separate room and floor info, so something is clearly being imported in a separate manner. I don't know why the device name then gets jumbled together.
But it's "fixed" for me, for now, and the wife no longer has that to complain about it.
I have some devices with possessives in the name. "Bill's Vanity" for example. Alexa often seems to get things wrong with names like that. So I've made it habit to use the 'Voice Command' field on devices to remove the apostrophe. So "Bill's Vanity" becomes just "Bills Vanity" and all is well.
I recently had some trouble with the Alexa-HS bridge and tried disabling the skill. This was a bad idea as the skill I'd been using was "an old one" and couldn't be re-enabled. When I tried using the new skill the devices all came in with the locations and name concatenated. What previously got imported as "Coffee Bar Lights" from the "1st floor" "Coffee Bar" now showed up in Alexa as "1st floor Coffee Bar Coffee Bar Lights" and voice commands to control just "Coffee Bar Lights" would fail.
So, something's going wrong with the importing. Yeah, that's not a great excuse when the wife starts complaining about why Alexa is broken.
I noticed that the error only happened on devices that DIDN'T have a Voice Command string entered.
This is my end-run around that problem.
I used a browser hack to delete only the devices with "HomeSeer" in the name from Alexa. From: https://lefkowitz.me/bulk-delete-sma...es-from-alexa/ and edited to use "HomeSeer" instead.
From a browser on the https://alexa.amazon.com/spa/index.html#appliances page I used this script in an F12 console window:
Code:
$x('//div[contains(text(), "HomeSeer")]') .map((innerDiv) => innerDiv.parentNode.parentNode) .map((parentDiv) => parentDiv.getElementsByTagName("button")[0]) .forEach((button) => { fetch( `https://alexa.amazon.com/api/phoenix/appliance/${button.getAttribute( "appliance-id" )}`, { method: "DELETE", } ); });
Once the devices were gone from Alexa, I ran this code as manual script in HS3:
Code:
Sub Main(ByVal Param As Object) Dim theCount theCount = 0 Dim Debug As Boolean = False Dim logName As String = "Voice_command: " Dim dv As Scheduler.Classes.DeviceClass Dim EN As Scheduler.Classes.clsDeviceEnumeration EN = hs.GetDeviceEnumerator If EN Is Nothing Then hs.WriteLog(logName, "Error getting Enumerator") Exit Sub End If Do dv = EN.GetNext If dv Is Nothing Then Continue Do Dim s Dim vc Dim av s = dv.name(Nothing) vc = dv.voicecommand(Nothing) av = dv.MISC_Check(Nothing, Enums.dvMISC.AUTO_VOICE_COMMAND) If (av) Then If (vc = "") Then hs.writelog(logName, "Name: " & s) hs.writelog(logName, "Voice: " & vc) hs.writelog(logName, "Auto: " & av) dv.voicecommand(Nothing) = dv.name(Nothing) hs.writelog(logName, "Voice command copied for: " & s) theCount += 1 End If End If Loop Until EN.Finished hs.writelog(logName, theCount & " voice devices detected without command.") End Sub
This marches through all of my HS3 devices and checks if they're voice enabled. If so, it checks to see if the voice command is empty. If so, it copies the device name into that field.
Once that was done I used the command "Alexa, discover devices" to re-import them.
This has solved my problem. I still question why the devices got imported that way. I have no idea if this is an Alexa problem or a Homeseer problem. Alexa does show the devices with separate room and floor info, so something is clearly being imported in a separate manner. I don't know why the device name then gets jumbled together.
But it's "fixed" for me, for now, and the wife no longer has that to complain about it.
Comment