HA plugin is terrific. Some help in scripting?

hamw
Posts: 1342
Joined: Mon Mar 31, 2008 7:45 pm

Re: HA plugin is terrific. Some help in scripting?

Post by hamw »

This script will turn on, set volume and set source for multiple zones, and may be easier than creating an action for each step. This script pulls the volume set from a global variable one can set from a control page. I have a button on a control page to execute the script to start, and am hoping to resurrect my whole house audio alarm clock, which will use this as well. I put in "Sonos" for the source, as that is what I usually listen to, but it would be easy to change the source with a global variable.

While one can also display the active source state as a word on a control page, one can only access the "source" in the control page device state menu when the source is active.

Also, it seems the zones need direct on/off commands, as toggle is not supported. And the command may throw an error, but it works.

I have a Sonos Port, and would like to be able to turn it on, play/pause and select sources. Right now those options don't seem available. But, "Sonos://" does open the app so it can be started manually.

Code: Select all

import indigo

var = indigo.variables[493724294] # "Radio_Wake_Up_Sonos"
VolSet = var.getValue(int)


indigo.device.turnOn(1737882882) #Kitchen
indigo.device.turnOn(641672610)  #Family Room
indigo.device.turnOn(1541557677) #Study Hallway
indigo.device.turnOn(1493860653) #LivRm DinRm
#indigo.device.turnOn(1644872590) #Game Rm
indigo.device.turnOn(536358103)  #MBR

indigo.dimmer.setBrightness(1737882882, value=VolSet)
indigo.dimmer.setBrightness(641672610, value=VolSet)
indigo.dimmer.setBrightness(1541557677, value=VolSet)
indigo.dimmer.setBrightness(1493860653, value=VolSet)
indigo.dimmer.setBrightness(536358103, value=VolSet)


HAPlugin = indigo.server.getPlugin("no.homeassistant.plugin")
if not HAPlugin.isEnabled():
	indigo.server.log("HomeAssistant Agent plugin not enabled")
	exit(0)

indigo.server.log("Setting source to Sonos")
HAPlugin.executeAction("media_play_set_source", deviceId=1737882882, props={'media_source': "Sonos"})
HAPlugin.executeAction("media_play_set_source", deviceId=641672610, props={'media_source': "Sonos"})
HAPlugin.executeAction("media_play_set_source", deviceId=1541557677, props={'media_source': "Sonos"})
HAPlugin.executeAction("media_play_set_source", deviceId=1493860653, props={'media_source': "Sonos"})
HAPlugin.executeAction("media_play_set_source", deviceId=536358103, props={'media_source': "Sonos"})
The only issue, which does not affect function, is that it throws a bunch of errors on execution, which I think could be related to the custom states.

Code: Select all

 Error                           device "06 Patio" state key source not defined
   Error                           device "06 Patio" state key source not defined
   Error                           device "06 Patio" state key source not defined
   Error                           device "06 Patio" state key source not defined
   Error                           device "07 Pool House" state key source not defined
   Error                           device "07 Pool House" state key source not defined
   Error                           device "05 Game Rm" state key source not defined
   Error                           device "05 Game Rm" state key source not defined
   Error                           device "01 Kitchen" state key source not defined
   Error                           device "01 Kitchen" state key source not defined
   Error                           device "01 Kitchen" state key source not defined
Last edited by hamw on Mon Mar 31, 2025 7:04 pm, edited 2 times in total.
hamw
Posts: 1342
Joined: Mon Mar 31, 2008 7:45 pm

Re: HA plugin is terrific. Some help in scripting?

Post by hamw »

@FlyingDiver,

I installed the just-updated plugin. In the version prior to this, the "source" device state would be available as a control page device state option , but only when the unit is already "on", and then the control page is the opened and modified. With the new plugin, the optional states don't show up? Was there a change in what's available?

I reverted back to the prior version and was able to get the source device state back on my control pages.

Also, while I had used this command before, and thought it worked:
indigo.device.turnOn(1737882882) #Kitchen
the new plugin now throws an error.

Code: Select all

Home Assistant Agent Warning    01 Kitchen: actionControlDimmerRelay: media_player.xantech8_kitchen does not support TurnOn
I tried it again in the prior version, and it definitely works, executing both turnOn and turnOff? Not sure what to make of the Home Assistant error?
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HA plugin is terrific. Some help in scripting?

Post by FlyingDiver »

Which version did you install?
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
hamw
Posts: 1342
Joined: Mon Mar 31, 2008 7:45 pm

Re: HA plugin is terrific. Some help in scripting?

Post by hamw »

I believe it is:

Code: Select all

<key>PluginVersion</key>
	<string>2025.0.5</string>
	<key>ServerApiVersion</key>
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HA plugin is terrific. Some help in scripting?

Post by FlyingDiver »

hamw wrote: Sun Mar 30, 2025 8:40 pm @FlyingDiver,

I installed the just-updated plugin. In the version prior to this, the "source" device state would be available as a control page device state option , but only when the unit is already "on", and then the control page is the opened and modified. With the new plugin, the optional states don't show up? Was there a change in what's available?

I reverted back to the prior version and was able to get the source device state back on my control pages.
This one I don't understand. There was some refactoring of the code, but I did not change anything regarding what states are created/updated.
hamw wrote: Sun Mar 30, 2025 8:40 pm Also, while I had used this command before, and thought it worked:
indigo.device.turnOn(1737882882) #Kitchen
the new plugin now throws an error.

Code: Select all

Home Assistant Agent Warning    01 Kitchen: actionControlDimmerRelay: media_player.xantech8_kitchen does not support TurnOn
I tried it again in the prior version, and it definitely works, executing both turnOn and turnOff? Not sure what to make of the Home Assistant error?
Yeah, that's my fault. I'm not sure exactly why, but I changed the device on and off commands to actually do a play/pause instead. And if the specific device doesn't support those commands, then you'll get that error.

I think the root problem is that the media_player device class is poorly designed, and has a whole bunch of "capability" flags which specify what commands are available. Which is really hard to map into the Indigo world. I need to look at that more and see if I can come up with a better solution.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
hamw
Posts: 1342
Joined: Mon Mar 31, 2008 7:45 pm

Re: HA plugin is terrific. Some help in scripting?

Post by hamw »

I reloaded the new plugin, but this time I stopped and re-started the server. It does show the "source" once the plugin is re-started. However, this dimmer action script, which works in 2024, does not work in 2025?

Code: Select all

indigo.device.turnOff(1737882882) #Kitchen
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HA plugin is terrific. Some help in scripting?

Post by FlyingDiver »

hamw wrote: Tue Apr 01, 2025 5:57 pm I reloaded the new plugin, but this time I stopped and re-started the server. It does show the "source" once the plugin is re-started. However, this dimmer action script, which works in 2024, does not work in 2025?

Code: Select all

indigo.device.turnOff(1737882882) #Kitchen
What HA device class is that?
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
hamw
Posts: 1342
Joined: Mon Mar 31, 2008 7:45 pm

Re: HA plugin is terrific. Some help in scripting?

Post by hamw »

It looks to me, from the device status and states list, that it functions like a dimmer. I also tried:

Code: Select all

indigo.dimmer.turnOn(1737882882) #Kitchen

indigo.dimmer.setBrightness(1737882882, value=15)
And it works as expected, turning the zone on and setting volume.

So I reloaded v2025.5, rebooted the Mac, and the dimmer on/off and set brightness commands do not work.

Code: Select all

 Embedded script executor host2 started
   Home Assistant Agent Warning    01 Kitchen: actionControlDimmerRelay: media_player.xantech8_kitchen does not support TurnOn
No issues; I will just go back to 2024. Not sure if this change may affect other HomeAssistant devices.
Attachments
Home Assistant Dayton Device States.png
Home Assistant Dayton Device States.png (35.18 KiB) Viewed 460 times
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: HA plugin is terrific. Some help in scripting?

Post by FlyingDiver »

I think I fixed the media player on/off issues. Please try https://github.com/FlyingDiver/Indigo-H ... g/2025.0.6
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
hamw
Posts: 1342
Joined: Mon Mar 31, 2008 7:45 pm

Re: HA plugin is terrific. Some help in scripting?

Post by hamw »

That got the dimmer device on/off and brightness working! Thanks!
Post Reply

Return to “Home Assistant Agent”