Skip to content

Flux Asset Control Actions

  • START_ASSET <asset_name>: Command to activate a specific asset.
  • STOP_ASSET <asset_name>: Command to deactivate a specific asset.
  • INSTALL_ASSET <asset_type>: Install an asset from Coreflux asset list.
  • INSTALL_ASSET <asset_type> AS <asset_name>: Install an asset from the Coreflux asset list and provides a name for the instance.
  • UNINSTALL_ASSET <asset_name>: Uninstall a specified asset.
  • PROVIDE_CONFIGURATION <asset_name> WITH <configuration>: Provide configuration for a specified asset.

Example

Example 1: This script listens for messages on the /motion MQTT topics, and then startes an asset if the motion detector changes to "detected".

ON MQTT_TOPIC /motion
    SET motionStatus FROM /motion MESSAGE

IF motionStatus EQUALS "detected"
    START_ASSET securityCamera
Explanation
  1. Set Motion Status When a message is received on the /motion MQTT topic, the motionStatus variable is set to the message received.

    ON MQTT_TOPIC /motion
        SET motionStatus FROM /motion MESSAGE
    
  2. Start Security Camera If the motionStatus variable is set to "detected", the securityCamera asset is started.

    IF motionStatus EQUALS "detected"
        START_ASSET securityCamera
    

    For example, if the motionStatus received is "detected", the securityCamera asset will be started.

Example 2:

ON MQTT_TOPIC /coreflux/commands
    IF MESSAGE == "install coreflux_modbus"
        INSTALL_ASSET coreflux_modbus
    END IF

ON MQTT_TOPIC /coreflux/configurations/coreflux_modbus
    SET config FROM /coreflux/configurations/coreflux_modbus MESSAGE
    PROVIDE_CONFIGURATION coreflux_modbus WITH config
    START_ASSET coreflux_modbus
Explanation

When a message is received on the /coreflux/commands MQTT topic, the INSTALL_ASSET command installs an asset from the Coreflux asset list if the message is "install coreflux_modbus". In this example, the coreflux_modbus asset is installed.

```plaintext
ON MQTT_TOPIC /coreflux/commands
    IF MESSAGE == "install coreflux_modbus"
        INSTALL_ASSET coreflux_modbus
    END IF
'''

When a configuration message is received on the /coreflux/configurations/coreflux_modbus MQTT topic, the PROVIDE_CONFIGURATION command provides the configuration for the coreflux_modbus asset and the START_ASSET command starts the coreflux_modbus asset.

```plaintext

ON MQTT_TOPIC /coreflux/configurations/coreflux_modbus
    SET config FROM /coreflux/configurations/coreflux_modbus MESSAGE
    PROVIDE_CONFIGURATION coreflux_modbus WITH config
    START_ASSET coreflux_modbus
'''
Note: The config variable in the above script is assumed to be a JSON object that includes the complete configuration for the coreflux_modbus asset.

FAQ

Can I install and configure assets via MQTT?

Yes, you can use the INSTALL_ASSET and PROVIDE_CONFIGURATION commands with MQTT topics to install and configure assets via MQTT.

Can I send configuration as a JSON object via MQTT?

Yes, you can send the configuration as a JSON object via MQTT and then use the SET command to assign the JSON object to a variable. Then, use the PROVIDE_CONFIGURATION command with the variable to provide the configuration.

Can I start an asset immediately after providing the configuration?

Yes, you can use the START_ASSET command immediately after the PROVIDE_CONFIGURATION command to start the asset.