Keep the light display OFF when AC turns ON?

Welcome to the SmartThings Community, @DVCamargo!

It’s not possible, there’s no way for us to know if a scene is done executing, what you can do is create a Rule using the last action of a scene as the trigger.
For example, if the last action is turning the AC on, you can use that as the trigger.

Another option would be to use a virtual momentary switch as the last action in a scene and then trigger a Routine based on the switch being pushed. I use this method to trigger Alexa to turn on/off/manage selections on my home theater receiver. I use this Edge driver [ST Edge] vEdge Creator: a virtual device generator for end users. If you don’t have a hub, you could create a virtual button using the ST Advanced Web App.

2 Likes

Hi everyone,

Thanks for the great discussion. I’ve successfully set up a cURL command to turn off the display light. To ensure the display stays off even after turning the AC back on, I set the command to run every minute. However, this causes the display to briefly light up each time before switching off.

I’m looking for a way to only execute the command if the display is on. Any ideas on how to achieve this?

Thanks for your help!

Best regards,
Georg

Hi everyone,

I tried to automate it with SmartThing Rules, and while the “if” condition and the “sleep” part work as expected, the “Light_ON” command doesn’t seem to be passing through.

Here’s the code snippet I’m using:


[
  {
    "if": {
      "equals": {
        "left": {
          "device": {
            "devices": [
              "62e454fc-df9a-0d25-008d-abeb78009dbb"
            ],
            "component": "main",
            "capability": "switch",
            "attribute": "switch"
          }
        },
        "right": {
          "string": "on"
        }
      },
      "then": [
        {
          "sleep": {
            "duration": {
              "value": {
                "integer": 10
              },
              "unit": "Second"
            }
          }
        },
        {
          "command": {
            "devices": [
              "62e454fc-df9a-0d25-008d-abeb78009dbb"
            ],
            "commands": [
              {
                "component": "main",
                "capability": "execute",
                "command": "execute",
                "arguments": [
                  {
                    "string": "mode/vs/0"
                  },
                  {
                    "map": {
                      "x.com.samsung.da.options": {
                        "string": "Light_On"
                      }
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  }
]

The “if” condition correctly identifies when the switch is “on,” and the “sleep” works, but the final command doesn’t seem to execute. Any suggestions on what might be wrong?

Hi guys. I made an automation to turn off the air conditioning LED after 5 seconds (rule valid only at night). In case you’re interested, the rule looks like this:

{
	"name": "Switching off the air conditioning display",
	"actions": [
		{
			"if": {
				"and": [
					{
						"between": {
							"value": {
								"time": {
									"reference": "Now"
								}
							},
							"start": {
								"time": {
									"reference": "Sunset"
								}
							},
							"end": {
								"time": {
									"reference": "Sunrise"
								}
							}
						}
					},
					{
						"equals": {
							"left": {
								"device": {
									"devices": [
										"my-ac-id"
									],
									"component": "main",
									"capability": "samsungce.airConditionerLighting",
									"attribute": "lighting"
								}
							},
							"right": {
								"string": "on"
							}
						}
					}
				],
				"then": [
					{
						"sleep": {
							"duration": {
								"value": {
									"integer": 5
								},
								"unit": "Second"
							}
						}
					},
					{
						"command": {
							"devices": [
								"my-ac-id"
							],
							"commands": [
								{
									"component": "main",
									"capability": "samsungce.airConditionerLighting",
									"command": "off",
									"arguments": []
								}
							]
						}
					}
				]
			}
		}
	]
}

With this automation, every time the LED comes on, after 5 seconds it goes off. I found this useful because, if I want to change the temperature in the middle of the night using the remote control, the LED will light up to indicate the new temperature, but it will off again in 5 seconds.

If you’re having trouble finding the ‘capability’ and ‘attribute’ related to your device’s LED, go to Samsung account, search for your device, scroll down to the list of attributes and search for ‘light’, you should see something like this:

Changing this attribute to on/off reflects on the air conditioning display, all I did was use it as a trigger, and whenever it goes on during the night, I set it to off again.

2 Likes

Hi, @Georg1
How did you confirm the “Sleep” section works?
Have you tried if the value “Light_Off” does something?

Thank you for the reply. I’ve tried the same code, but instead of switching off the light I put in some coat switch off the AC unit which worked perfectly. So I know that the Statement to sleep segment work.

Command light_on works if I send it over cURL.

This is my workaround since I couldn’t get it to work directly with SmartThings rules. Instead, I’m running a bash script from my Homebridge server that automates control of my two AC units by checking their state and triggering the actions to turn the display light off when needed.

Step-by-Step Guide:

1. Set Up Your Device IDs and API Token

First, get your device IDs and API token from the SmartThings Developer Workspace and API dashboard.

This setup is specifically for two AC units, but you can adjust it for more if needed. Replace these placeholders in the script:

  • YOUR_DEVICE_ID_1: Your first AC’s device ID.
  • YOUR_DEVICE_ID_2: Your second AC’s device ID.
  • YOUR_API_TOKEN: Your SmartThings API token.

2. Create the Bash Script

Here’s the script that checks the state of both AC units and triggers actions accordingly. The script will keep the AC display on for the first 5 minutes (300 seconds) after it turns on, then turn it off:

#!/bin/bash

# File paths to store the last known states of the AC units
STATE_FILE_1="/home/pi/ac1_last_state.txt"
STATE_FILE_2="/home/pi/ac2_last_state.txt"

# Function to get the current state of an AC unit using its device ID
get_current_state() {
    curl -s -X GET "https://api.smartthings.com/v1/devices/$1/status" \
    -H "Authorization: Bearer YOUR_API_TOKEN" | grep -o '"switch":{"value":"[^"]*' | grep -o '[^"]*$'
}

# Function to trigger an action on the AC unit (e.g., turning off the display)
trigger_ac() {
    curl -L -X POST "https://api.smartthings.com/v1/devices/$1/commands" \
    -H "Authorization: Bearer YOUR_API_TOKEN" \
    -H "Content-Type: application/json" \
    --data-raw '{"commands":[{"component":"main","capability":"execute","command":"execute","arguments":["mode/vs/0",{"x.com.samsung.da.options":["Light_On"]}]}]}'
}

# Read the last known states from the state files
LAST_STATE_1=$(cat "$STATE_FILE_1")
LAST_STATE_2=$(cat "$STATE_FILE_2")

# Query the current states of the AC units
CURRENT_STATE_1=$(get_current_state "YOUR_DEVICE_ID_1")
CURRENT_STATE_2=$(get_current_state "YOUR_DEVICE_ID_2")

# Immediately update the state files with the current states
echo "$CURRENT_STATE_1" > "$STATE_FILE_1"
echo "$CURRENT_STATE_2" > "$STATE_FILE_2"

# Check if either AC unit has been turned on (changed from "off" to "on")
if [ "$LAST_STATE_1" = "off" -a "$CURRENT_STATE_1" = "on" ] || [ "$LAST_STATE_2" = "off" -a "$CURRENT_STATE_2" = "on" ]; then
    sleep 300  # Wait 5 minutes before taking further action (e.g., turning off the display)

    # Trigger the action for the first AC unit if it has been turned on
    if [ "$LAST_STATE_1" = "off" -a "$CURRENT_STATE_1" = "on" ]; then
        trigger_ac "YOUR_DEVICE_ID_1" &
    fi

    # Trigger the action for the second AC unit if it has been turned on
    if [ "$LAST_STATE_2" = "off" -a "$CURRENT_STATE_2" = "on" ]; then
        trigger_ac "YOUR_DEVICE_ID_2" &
    fi

    # Wait for all background processes (if any) to complete before the script exits
    wait
fi

3. Set Up the Cron Job

Run the script every minute with a cron job:

  1. Open crontab:
    crontab -e
    
  2. Add the cron job:
    * * * * * /home/pi/ac_on_trigger.sh
    
    Replace /home/pi/ac_on_trigger.sh with the correct path to your script.

4. Test It Out

The script should now check the state of both your AC units every minute and, if either AC turns on, it will keep the display on for the first 5 minutes before turning it off. Make sure to replace the placeholders with your API token and device IDs.


This setup has worked great for controlling my two AC units, and I hope it helps you too!

Hi, @Georg1
Does the cURL command work even when the AC unit is turned off? I don’t know if the issue could be that commands are rejected after the device is turned off.
If it works, then something else could be happening, let me know if you want to open an investigation about that, I see you found a workaround and we would need to collect some info.

Thank you . I got quite the same instructions from my Brazilian colleagues and worked too.

Thanks

1 Like