Toggle Power On PC
Domoticz

Toggle Power On PC

The purpose of this script is to ensure that the AWTRIX3 device is powered in sync with the PC device, turning the AWTRIX3 device on when the PC is turned on and off when the PC is turned off. This can be useful for managing power usage or ensuring certain devices are only active when necessary.
A flow by Galadril

Download flow

Flow Details

  1. πŸ”„ Activation and Scope:

    • The script is active, as indicated by active = true.
    • It listens for state changes specifically from the device labeled 'PC'.
  2. πŸ“ Logging:

    • The script logs information messages with a marker labeled "AWTRIX3_APP". This helps in identifying logs related to this specific script.
    • The level of logging is set to domoticz.LOG_INFO, meaning informational messages will be recorded.
  3. βš™οΈ Execution Logic:

    • The execute function is triggered whenever there is a change in the state of the 'PC' device.

    • When the PC device state changes to 'On':

      • The script checks if the 'AWTRIX3 - Power' device is not already 'On'.
      • If it isn't ('On'), the script turns it 'On' 🟒 and logs an informational message stating that 'AWTRIX3 - Power' was turned on because 'PC' is on.
    • When the PC device state changes to 'Off':

      • The script checks if the 'AWTRIX3 - Power' device is not already 'Off'.
      • If it isn't ('Off'), the script turns it 'Off' πŸ”΄ and logs an informational message stating that 'AWTRIX3 - Power' was turned off because 'PC' is off.

πŸ”Œ Purpose: The purpose of this script is to ensure that the AWTRIX3 device is powered in sync with the PC device, turning the AWTRIX3 device on when the PC is turned on and off when the PC is turned off. This can be useful for managing power usage or ensuring certain devices are only active when necessary.

More information:

Domoticz: www.domoticz.com

Domoticz AWTRIX3 Plugin: https://github.com/galadril/Domoticz-AWTRIX3-Plugin

123456789101112131415161718192021222324252627282930
return {
    active = true,

    on = {
        devices = {
            'PC'
        }
    },

    logging = {
        level = domoticz.LOG_INFO,
        marker = "AWTRIX3_APP"
    },

    execute = function(domoticz, device)
        local targetDevice = domoticz.devices('AWTRIX3 - Power')

        if device.state == 'On' then
            if targetDevice.state ~= 'On' then
                targetDevice.switchOn()
                domoticz.log('Turned on AWTRIX3 - Power because PC is On.', domoticz.LOG_INFO)
            end
        elseif device.state == 'Off' then
            if targetDevice.state ~= 'Off' then
                targetDevice.switchOff()
                domoticz.log('Turned off AWTRIX3 - Power because PC is Off.', domoticz.LOG_INFO)
            end
        end
    end
}
-- Flow first published on January 2, 2025.