HA plugin is terrific. Some help in scripting?

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

HA plugin is terrific. Some help in scripting?

Post by hamw »

HA plugin has been perfect in accessing my Unifi cameras, setting up iAqualink, and now my Dayton Dax88. Running into some coding issues with setting volume and source on the Dax88? Could you please look at this script? It has a lot of logging to see what's going on.

Code: Select all

import indigo

# Device ID for the Dayton DAX88 media player
DEVICE_ID = 1737882882

# Variable IDs for source and volume
VOLUME_VARIABLE_ID = 1208421489
SOURCE_VARIABLE_ID = 1416651045

indigo.server.log("Script started: Preparing to update the Dayton device.")

# Step 1: Retrieve the current volume variable value
try:
    indigo.server.log("Retrieving volume variable...")
    volume_variable = indigo.variables[VOLUME_VARIABLE_ID]
    volume_value = int(volume_variable.value)  # Convert volume to integer (assumed 0–100 scale)
    indigo.server.log(f"Volume variable retrieved: {volume_value}")
except Exception as e:
    indigo.server.log(f"Error retrieving or parsing volume variable: {e}", isError=True)

# Step 2: Retrieve the current source variable value
try:
    indigo.server.log("Retrieving source variable...")
    source_variable = indigo.variables[SOURCE_VARIABLE_ID]
    source_value = source_variable.value  # Assume source is stored as a string
    indigo.server.log(f"Source variable retrieved: {source_value}")
except Exception as e:
    indigo.server.log(f"Error retrieving or parsing source variable: {e}", isError=True)

# Step 3: Adjust the volume using an Indigo-supported action
try:
    indigo.server.log(f"Setting volume to {volume_value}% for device ID {DEVICE_ID}...")
    
    # Replace "setVolume" with the exact method name for your device
    indigo.device.executeAction("setVolume", deviceId=DEVICE_ID, props={"volume": volume_value})
    indigo.server.log(f"Volume successfully set to {volume_value}% for device ID {DEVICE_ID}.")
except Exception as e:
    indigo.server.log(f"Error setting volume: {e}", isError=True)

# Step 4: Adjust the source using an Indigo-supported action
try:
    indigo.server.log(f"Setting source to '{source_value}' for device ID {DEVICE_ID}...")
    
    # Replace "setInputSource" with the exact method name for your device
    indigo.device.executeAction("setInputSource", deviceId=DEVICE_ID, props={"source": source_value})
    indigo.server.log(f"Source successfully set to '{source_value}' for device ID {DEVICE_ID}.")
except Exception as e:
    indigo.server.log(f"Error setting source: {e}", isError=True)

indigo.server.log("Script completed.")
It keeps throwing these errors:

Code: Select all

   Script                          Script started: Preparing to update the Dayton device.
   Script                          Retrieving volume variable...
   Script                          Volume variable retrieved: 60
   Script                          Retrieving source variable...
   Script                          Source variable retrieved: 1
   Script                          Setting volume to 60% for device ID 1737882882...
   Script Error                    Error setting volume: 'DeviceCmds' object has no attribute 'executeAction'
   Script                          Setting source to '1' for device ID 1737882882...
   Script Error                    Error setting source: 'DeviceCmds' object has no attribute 'executeAction'
   Script                          Script completed.
Here's what CoPilot says:
The persistent mention of "DeviceCmds" suggests that the Indigo scripting engine is automatically associating the DEVICE_ID (1737882882) with its internal representation of a media player device, known as a "DeviceCmds" object. This is not hidden in the script but is part of how Indigo identifies and manages devices internally. Essentially, Indigo assigns certain methods and properties to device objects based on their device type, and "DeviceCmds" is the base class for managing devices.

Here’s what this means:

"DeviceCmds" Object: This indicates that the device you’re trying to control is recognized as a standard Indigo device, but the methods being called (executeAction, updateStateOnServer) are not applicable to this particular class of device.

Unsupported Actions: The error is specifically telling you that "DeviceCmds" doesn't have the executeAction or updateStateOnServer methods available for use. This is because these methods are either specific to other device types or are not implemented for your Dayton device.
Any thoughts would be appreciated!
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 »

You have to call the executeAction method for the plugin, not the device. See https://wiki.indigodomo.com/doku.php?id ... go_plugins

Here's a simple example from the BetterEmail plugin docs:

Code: Select all

def sendAlertEmail(subject, message):
    bePlugin = indigo.server.getPlugin("com.flyingdiver.indigoplugin.betteremail")
    if bePlugin.isEnabled():
        bePlugin.executeAction("sendEmail", deviceId=12345678, props={'emailTo':'[email protected]', 'emailSubject': subject, 'emailMessage': message})
    return

sendAlertEmail("Test Alert", "This is only a test")
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
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 »

It doesn't really matter anyway, since the plugin does not implement the "setVolume" and "setInputSource" actions you're specifying. There are actions to do those things, but those are not the names.

Is there some reason you're doing this in a script rather than using the Indigo UI and an action group? Those should work. Scripting support is not really implemented or documented at this time.

That's all I have time for today, I've got a road trip I need to get to.
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 »

Appreciate your taking the time, and enjoy your trip.

Yes, I'd like to easily change multiple zones at once, modifying volume in particular but also occasionally changing source. I can do it with triggers and actions, but I figure some simple code would be easier in the long run.
hamw
Posts: 1342
Joined: Mon Mar 31, 2008 7:45 pm

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

Post by hamw »

I tried to set the brightnessLevel with some scripts CoPilot wrote, but don't seem to be able to execute an action. This is the last one, trying to set the audio zone volume level to an Indigo Variable, the error, and CoPilot's comments. Since the plugin has both volume and brightnessLevel, both were tried.

Code: Select all

import indigo

# Plugin ID and Device ID
PLUGIN_ID = "no.homeassistant.plugin"
DEVICE_ID = 1737882882

# Variable ID for volume
VOLUME_VARIABLE_ID = 1208421489

indigo.server.log("Script started: Testing plugin actions for Dayton device.")

# Step 1: Retrieve the volume variable value
try:
    indigo.server.log("Retrieving volume variable...")
    volume_variable = indigo.variables[VOLUME_VARIABLE_ID]
    volume_value = int(volume_variable.value)  # Convert volume to integer
    indigo.server.log(f"Volume variable retrieved: {volume_value}")
except Exception as e:
    indigo.server.log(f"Error retrieving or parsing volume variable: {e}", isError=True)

# Step 2: Test a generic plugin action
try:
    indigo.server.log(f"Testing plugin action to update volume for device ID {DEVICE_ID}...")
    
    # Retrieve the plugin
    plugin = indigo.server.getPlugin(PLUGIN_ID)
    if plugin.isEnabled():
        # Replace 'testActionID' with potential valid actions (e.g., 'adjustBrightness', 'setVolume', etc.)
        plugin.executeAction(
            "testActionID",  # Replace with a guessed or known action ID
            deviceId=DEVICE_ID,
            props={"brightnessLevel": volume_value}  # Update property key if needed
        )
        indigo.server.log(f"Plugin action executed successfully.")
    else:
        indigo.server.log(f"Plugin {PLUGIN_ID} is not enabled!", isError=True)
except Exception as e:
    indigo.server.log(f"Error executing plugin action: {e}", isError=True)

indigo.server.log("Script completed.")

What to Confirm
Inspect Known Action IDs:

Try running the script with different action IDs and check for success.

Plugin Feedback:

Use any available information from the creator or plugin panel to refine the action ID and property keys.

Let me know if additional details from the plugin emerge. With more insight into the plugin’s behavior, we can pinpoint the solution!

Code: Select all

Script Script started: 
Testing plugin actions for Dayton device. 
Script Retrieving volume variable
Script Volume variable retrieved: 22 
Script Testing plugin action to update volume for device ID 1737882882
Script Error Error executing plugin action: plugin does not have a <CallbackMethod> specified for action id testActionID 
Script Script completed.
Thank you for running the test! Based on the log, the plugin clearly does not recognize testActionID, which confirms we're still missing the valid action IDs required to update brightnessLevel or volume_level. Without knowing the exact IDs for plugin-supported actions, we can only test potential IDs or lean on other ways to inspect the plugin configuration.

Where Do We Stand?
At this point, it’s clear the plugin has specific, pre-defined actions and methods that must be used to modify states such as brightnessLevel or volume_level. Since testActionID failed, we’ll need to narrow down the possibilities based on the plugin’s intended functionality.

Approach Moving Forward
1. Review the Plugin and Device Integration
Ensure the no.homeassistant.plugin documentation is checked for a list of supported actions.

If no documentation exists, try to inspect the plugin's configuration or reach out to its creator. They may clarify the specific actions available.

2. Test Common Action IDs
The most logical action IDs for brightness or volume control are:

"setBrightness"

"adjustBrightness"

"setVolumeLevel"

"adjustVolumeLevel"

Replace testActionID with these possibilities, and monitor the logs for feedback.

3. Consult Plugin Logs
Enable detailed logging for the plugin (if supported). This may show attempted actions and expected formats for any failed calls, giving us more clues.

4. Revisit Indigo’s UI
Look at the device properties or settings panel within Indigo to see if there are any specific controls or integrations tied to the plugin.

Alternative Path
If the plugin actions remain elusive:

We can investigate more general plugin behaviors by reaching out to the Indigo community or plugin developers.
/quote]
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 »

brightnessLevel is a standard Indigo action for dimmer type devices, which the media entity mimics for volume control. Look at the Indigo wiki for scripting commands to set brightness (aka volume for this device).
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
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 »

And in the future, please don’t quote CoPilot output. It’s not as smart as it thinks it is and its output isn’t really useful.
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 agree, CoPilot should stay on the ground! Thank you for your advice; this script works fine.

Code: Select all

import indigo
from time import sleep

KitchenBrightness = indigo.devices[1737882882]
var = indigo.variables[1208421489] # "Volume Setpoint"
VolSet = var.getValue(int)
indigo.dimmer.setBrightness(1737882882, value = VolSet)
What device type and action would I use to script a source change? Seems like it must be a different type of device rather than a dimmer?

Much appreciated!
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

HA plugin is terrific. Some help in scripting?

Post by FlyingDiver »

Yeah, that will require a plugin specific action. You can determine the action name and parameters by looking at the Actions.xml file in the plugin.

I’m not sure if it’s documented anywhere how to figure out the script syntax from reading the XML. At least in a generic way.

Go back and look at the example script from BetterEmail I posted above. The key items are the action name and the props for that action.

Sent from my iPhone using Tapatalk
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
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 »

Here's the section of Actions.xml for setting the source:

Code: Select all

    <Action id="media_play_set_source" deviceFilter="self.ha_media_player">
        <Name>Set Media Player Source</Name>
        <CallbackMethod>media_play_set_source_action</CallbackMethod>
        <ConfigUI>
            <Field id="media_source" type="menu">
                <Label>Media Source:</Label>
                 <List class="self" filter="" method="media_player_source_list" dynamicReload="true"/>
            </Field>
        </ConfigUI>
    </Action>
    
So the action name is "media_play_set_source_action". It has one property, "media_source". The value of that is something that is derived from the attributes of the media_player entity, and I honestly have no idea whether it's a string name or a string number or an actual number. If you use that action in an action group in the Indigo UI, with debug logging enabled, it'll show the source identifier in the Indigo log. From that, you should be able to create your script.
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 »

The Dayton has 8 possible named source inputs. I'm hoping to set the source by changing the name of the variable so that I can tap a control page button that scrolls through the possible inputs, rather than have individual buttons. Here are the debug actions and names:

Code: Select all

 Home Assistant Agent Debug      01 Kitchen: media_player_on_action for media_player.xantech8_kitchen
   Home Assistant Agent Debug      01 Kitchen: media_player_set_volume_action for media_player.xantech8_kitchen
   Home Assistant Agent Debug      00 Sonos: media_player_media_play_action for media_player.family_room
   Home Assistant Agent Debug      01 Kitchen: media_play_set_source_action: Sonos for media_player.xantech8_kitchen
   Home Assistant Agent Debug      call_service event: media_player turn_on ['media_player.xantech8_kitchen']
   Home Assistant Agent Debug      call_service event: media_player turn_on ['media_player.xantech8_kitchen']
   Home Assistant Agent Debug      call_service event: media_player volume_set ['media_player.xantech8_kitchen']
   Home Assistant Agent Debug      call_service event: media_player media_play ['media_player.family_room']
   Home Assistant Agent Debug      call_service event: media_player select_source ['media_player.xantech8_kitchen']
   Home Assistant Agent Debug      call_service event: media_player volume_set ['media_player.xantech8_kitchen']
   Home Assistant Agent Debug      call_service event: media_player media_play ['media_player.family_room']
   Home Assistant Agent Debug      call_service event: media_player select_source ['media_player.xantech8_kitchen']
Based on the Better Email example, and reading the linked Indigo examples, here is what I came up with. This script would be in a trigger that fires when the varSourceSelect variable changes. While it doesn't throw an error, it doesn't update the device either.

Code: Select all

varSource_Select = indigo.variables[309867966]
Zone_Kitchen = indigo.devices[1737882882]
def media_play_set_source_action(select_source):
	HAPlugin = indigo.server.getPlugin("no.homeassistant.plugin")
	if HAPlugin.isEnabled():
		HAPlugin.executeAction("media_play_set_source_action", Zone_Kitchen, props={'select_source': varSource_Select})
return
thanks for looking at it!
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 »

A couple problems with your script. First, as you can see in the BetterEmail script above, the second argument to the executeAction() method is the DeviceID, not the device object itself. Second, the value of the "select_source" entry in the props dictionary needs to be the identifier for the source you want, not an Indigo variable object.

The following might work. I fixed the deviceID, and it uses the value of the source select variable, not the variable object.

Code: Select all

varSource_Select = indigo.variables[309867966].value
def media_play_set_source_action(select_source):
	HAPlugin = indigo.server.getPlugin("no.homeassistant.plugin")
	if HAPlugin.isEnabled():
		HAPlugin.executeAction("media_play_set_source_action", deviceId=1737882882, props={'select_source': varSource_Select})
return
Turn on detailed debugging when you run this and see if you get an error message returned from the HA server.
joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177
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 »

This script works. Generalizing it to work with your devices is up to you.

Code: Select all

import indigo

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 Tuner")
HAPlugin.executeAction("media_play_set_source", deviceId=608437088, props={'media_source': "Tuner"})
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 »

Thank you so much. This works:

Code: Select all

import indigo

varSource_Select = indigo.variables[309867966].value
Zone_Kitchen = indigo.devices[1737882882]  #for housekeeping

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 Cable")
HAPlugin.executeAction("media_play_set_source", deviceId= 1737882882, props={'media_source': varSource_Select})
Really appreciate the help. Glad I came closer this time.
hamw
Posts: 1342
Joined: Mon Mar 31, 2008 7:45 pm

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

Post by hamw »

The Home Assistant device is also scriptable as an indigo device to turn it on and off. I modified the Indigo desk lamp example.

Code: Select all

if indigo.devices['Kitchen_Media'].onState == False:
    # Desk Lamp is off. Save the "false" state into the OldDeskLampState variable.
    indigo.variable.updateValue(indigo.variables['audio_1_On_Off_State'], "false")
    # Now turn on the Desk Lamp.
    indigo.device.turnOn('Kitchen_Media')
else:
    # Desk Lamp is on. Save the "true" state into the OldDeskLampState variable.
    indigo.variable.updateValue(indigo.variables['audio_1_On_Off_State'], "true")
    # Now turn off the Desk Lamp.
    indigo.device.turnOff('Kitchen_Media')
Post Reply

Return to “Home Assistant Agent”