Can smart Samsung washing machines be started with the SmartThings integration?

@eldigo - I tried to create a REST sensor for the remote control, as follows;

sensor:
  - platform: rest
    resource: https://api.smartthings.com/v1/devices/4ffb6b63-XXXX-XXX-XXX-67421a52a09c/components/main/capabilities/remoteControlStatus/status
    method: GET
    headers: 
      Authorization: Bearer 9c2cf8cd-XXXX-XXXX-XXXX-6c98ab0873f1
    value_template: '{{ "Off" if value_json.remoteControlEnabled.value == false else "On" }}'
    name: Washer Remote Status

But it didn’t work.
Using CURL the status of the remote control comes back properly, so I know the API call with heards is correct. The response body is as follows:

{
    "remoteControlEnabled": {
        "value": "true",
        "timestamp": "2023-07-19T19:18:59.278Z"
    }
}

So I do get the sensor created, but it doesn’t update. There are no errors in the log.
Any idea where I got lost in the syntax?
(By the way - I have lots of other REST sensors that works just fine)

[Edit] I found the error. The JSON value has to be surrounded by double quotes because the API returns it as a string and not as a boolean.

Thanks I’ll play with that. I’ve got it set up, it shows as On since that was the last status of the washer before it powered off.

So I think maybe the value template should check the state of the washer power switch, switch.washer?

I decided to modify the above statement as shown. It is accepted as best practice to assume default to be “true”.
Apart from that, my washer changes the status of the remote control to “off” when the machine is turned off.

I have a switch working for starting my Samsung washing machine using a command line switch, but only if I have pre-programmed the machine manually. This means I have to put in all the right settings, and then press the “Smart Control” button.

I have 2 questions for people on here that are smarter than me:

  1. Is it possible to set up the machine and all without doing the settings on the machine manually?
  2. Is there a way to use the API to check whether the machine is connected? This is because occasionally my machine drops the wifi connection, and I’d like to test this so I can fix it proactively.

Where does the first bit of code go in HA?

I understand the second bit of code goes into my configuration yaml

I have the same setup as you and want the same result so I just need a little nudge in the right direction. Not too sure which bits I change to my own details

Thank you

Can you share how you got it all working please? Someone said earlier in this thread but it is very vague.

I’m not sure how familiar or not you are with calling API’s so this could be too much detail, but this may hopefully help a few people.

Some context around my take on the automation: you could do it based on the properties of the device. For example when remote control is enabled and the state is set to stop. That probably means it’s ready to go as you would only press the button on the machine when you’ve set up a load of washing.
But when I found that the stop/start state of the appliances are not trustworthy (or at least not when I tested and later accidentally started the washing machine and dryer), I still like the idea of having a separate switch. Hence my wait for the home assistant yellow as I don’t have any support for zigbee in my home yet.
Instead of relying on the device, a cheap sonoff zigbee switch will set a helper (a toggle “washerAutoStart” to “On”) to indicate I want my appliance to start going when certain conditions have been met (e.g. producing enough solar). This means that when either it’s set to go and power production it should start, or when you already have met the power threshold it should also trigger when the button is pressed as it could then immediately start.

1. Generate bearer token
https://account.smartthings.com/tokens
See more detailed instructions here on the personal access token: SmartThings - Home Assistant

2. Get the device IDs
Required for each device (washer/dryer)

URL / endpoint: https://api.smartthings.com/v1/devices/
This call lists all your devices. Get the device_id value of the appliance

Or step by step:
a. Have something to test your API calls like postman: Download Postman | Get Started for Free
b. Create a new entry (a “GET” request)
c. URL: https://api.smartthings.com/v1/devices/
d. In the Authorization tab, choose Bearer as the Type and enter the token
e. Send the API call - you should see a 200 OK response
f. Review the API response at the bottom. Find the entry of your appliance and take note of the deviceId value

3. Configuration.yaml
Add the following commands to configuration.yaml so we can call them using a HA service:

shell_command:
  # Washing machine
  washer_start: 'curl --location --request POST ''https://api.smartthings.com/v1/devices/DEVICEID/commands'' --header ''Authorization: Bearer TOKEN'' --header ''Content-Type: text/plain'' --data-raw ''[    {   "capability":"washerOperatingState",        "command":"setMachineState",        "arguments":["run"]    }]'''
  washer_pause: 'curl --location --request POST ''https://api.smartthings.com/v1/devices/DEVICEID/commands'' --header ''Authorization: Bearer TOKEN'' --header ''Content-Type: text/plain'' --data-raw ''[    {   "capability":"washerOperatingState",        "command":"setMachineState",        "arguments":["pause"]    }]'''
  washer_stop: 'curl --location --request POST ''https://api.smartthings.com/v1/devices/DEVICEID/commands'' --header ''Authorization: Bearer TOKEN'' --header ''Content-Type: text/plain'' --data-raw ''[    {   "capability":"washerOperatingState",        "command":"setMachineState",        "arguments":["stop"]    }]'''

We only need the one to start, but you could pause or stop a cycle using a button on the dashboard for example
Just replace TOKEN with the token from step one and replace DEVICEID with the device id from step two.

4. Automations

Automation 1:

Zigbee switch:
Triggers

  • Switch is pressed

Actions

  • Set the “washerAutoStart” boolean to TRUE

Automation 2:

Triggers

  • When inverter (state number value) is above (whatever value is appropriate)
    Or you could even do something more complex if you subtract power usage from production but I’m probably happy if it produces 2kw, 3kw or something like that
  • When input_boolean.washerAutoStart is changed state to On

Conditions

  • When inverter is above (whatever value is appropriate)
    AND
  • When input_boolean.washerAutoStart is changed state to On

Basically the same as triggers, as either trigger could have started the automation but both conditions have to be met before we want to turn the appliance on

Actions

  • Call the service shell command washer_start
  • Set the value of input_boolean.washerAutoStart to Off
  • Add a notification action if needed…
3 Likes

I didn’t have a note of my token so I generated a new one but as it is a different token to the one I used to initially setup the smarthings integration and devices, will this cause a problem?

I cannot seem to get to the next stage when I try and create an automation, I cannot find anyhtign called ‘washer_start’ etc

Here is the code I have put at the end of my configuration yaml

# Washing machine
washer_start: 'curl --location --request POST ''https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-1*******/commands'' --header ''Authorization: Bearer *******-0445-4d37-afad-******'' --header ''Content-Type: text/plain'' --data-raw ''[    {   "capability":"washerOperatingState",        "command":"setMachineState",        "arguments":["run"]    }]'''
washer_pause: 'curl --location --request POST ''https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-*******/commands'' --header ''Authorization: Bearer ******-0445-4d37-afad-*****'' --header ''Content-Type: text/plain'' --data-raw ''[    {   "capability":"washerOperatingState",        "command":"setMachineState",        "arguments":["pause"]    }]'''
washer_stop: 'curl --location --request POST ''https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-*******/commands'' --header ''Authorization: Bearer ******-0445-4d37-afad-******'' --header ''Content-Type: text/plain'' --data-raw ''[    {   "capability":"washerOperatingState",        "command":"setMachineState",        "arguments":["stop"]    }]'''

Obviously the ***** are where I have hidden my details

I have formatted my code the same way you uploaded yours to this forum but I’m now thinking that it uploaded wrong and you don’t have just 3 really long lines of code, they should be broken up into different lines. Am I right?

You can have multiple tokens. If the API call worked in postman, it meant you’ve successfully used the new token to authorise yourself. You can always delete the old token from the Samsung site if you’re no longer using it.

The zigbee button is just my preference, you can definitely do it entirely without and change the automation trigger and conditions to when the washing machine state is “stop” AND when remote control is enabled to turn it on.

Did you put those 3 lines under the section ?

shell_command:

Once that works, you can validate that the 3 services are created and that you can start the washing machine by calling the service under the developer tools → services
image

Did I put those 3 lines under what section?

I put them in the config yaml at the bottom like this but I am getting the error below

# Washing machine
washer_start: 'curl --location --request POST "https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-909090/commands" 
--header "Authorization: Bearer 8e3df9de-0445-4d37-afad-90909" 
--header "Content-Type: text/plain"
--data-raw "[
      {
          "capability":"washerOperatingState",
          "command":"setMachineState",
          "arguments":["run"]

washer_pause: 'curl --location --request POST "https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-9/comm90090ands"
--header "Authorization: Bearer 8e3df9de-0445-4d37-afad-0"90909
--header "Content-Type: text/plain" 
--data-raw "[
      {
          "capability":"washerOperatingState",
          "command":"setMachineState",
          "arguments":["pause"]

washer_stop: 'curl --location --request POST "https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-9/com9000mands" 
--header "Authorization: Bearer 8e3df9de-0445-4d37-afad-09090" 
--header "Content-Type: text/plain" 
--data-raw "[
      {
          "capability":"washerOperatingState",
          "command":"setMachineState",
          "arguments":["stop"]
    }
]'

File ‘configuration.yaml’ could not be parsed, it was referenced from path ‘configuration.yaml’.This file will be ignored. Error(s): - YAMLSyntaxError: All collection items must start at the same column - YAMLSemanticError: Multi-line single-quoted string needs to be sufficiently indented - YAMLSemanticError: Multi-line single-quoted string needs to be sufficiently indented - - And 9 more errors…

Thought I got rid of the error but it is back

File ‘configuration.yaml’ could not be parsed, it was referenced from path ‘configuration.yaml’.This file will be ignored. Error(s): - YAMLSemanticError: Multi-line single-quoted string needs to be sufficiently indented - YAMLSemanticError: Multi-line single-quoted string needs to be sufficiently indented - YAMLSemanticError: Multi-line single-quoted string needs to be sufficiently indented

this is now my code

shell_command:
# Washing machine
washer_start: 'curl --location --request POST "https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-999/commands"
--header "Authorization: Bearer 8e3df9de-0445-4d37-afad-999"
--header "Content-Type: text/plain"
--data-raw "[
      {
          "capability":"washerOperatingState",
          "command":"setMachineState",
          "arguments":["run"]
              }
]'
washer_pause: 'curl --location --request POST "https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-999/commands"
--header "Authorization: Bearer 8e3df9de-0445-4d37-afad-999"
--header "Content-Type: text/plain"
--data-raw "[
      {
          "capability":"washerOperatingState",
          "command":"setMachineState",
          "arguments":["pause"]
              }
]'
washer_stop: 'curl --location --request POST "https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-999/commands"
--header "Authorization: Bearer 8e3df9de-0445-4d37-afad-999"
--header "Content-Type: text/plain"
--data-raw "[
      {
          "capability":"washerOperatingState",
          "command":"setMachineState",
          "arguments":["stop"]
    }
]'

You cannot add line breaks in like that. It’s yaml and it requires the right indentation too. Using your values this should validate just fine:

shell_command:
# Washing machine
  washer_start: 'curl --location --request POST ''https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-1*******/commands'' --header ''Authorization: Bearer *******-0445-4d37-afad-******'' --header ''Content-Type: text/plain'' --data-raw ''[    {   "capability":"washerOperatingState",        "command":"setMachineState",        "arguments":["run"]    }]'''
  washer_pause: 'curl --location --request POST ''https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-*******/commands'' --header ''Authorization: Bearer ******-0445-4d37-afad-*****'' --header ''Content-Type: text/plain'' --data-raw ''[    {   "capability":"washerOperatingState",        "command":"setMachineState",        "arguments":["pause"]    }]'''
  washer_stop: 'curl --location --request POST ''https://api.smartthings.com/v1/devices/dfe8dba1-fe99-9897-c896-*******/commands'' --header ''Authorization: Bearer ******-0445-4d37-afad-******'' --header ''Content-Type: text/plain'' --data-raw ''[    {   "capability":"washerOperatingState",        "command":"setMachineState",        "arguments":["stop"]    }]'''

Thank you.

I have put that in to my configuration.yaml and there was an error at first. I then came out of the file editor and then back in and the error no longer shows. They still do not show up in the service section or an automation.

Home assistant reboot is all that was required.

You sir are awesome, thank you so much.

I love this community.

Can I ask though, how do you select a specific wash programme?

And with regards to the automation, I don’t get an option to select ‘call service’ in triggers or conditions so cannot input the boolean part

Glad you got it to work. And yes, configuration.yaml changes usually require a restart.
When you create a new automation, choose “Call Service” under the actions dropdown. After that you should be able to find those new services you’ve created.

image

I think for the washing cycle someone mentioned it either in this thread or another.

The Samsung API documentation can be a bit limited, but do a GET request in postman to:
https://api.smartthings.com/v1/devices/DEVICEID/components/main/capabilities/samsungce.washerCycle/status

That should return the codes for all supported cycles for your machine.
image

It’s probably a bit of testing standing next to the machine to see that it picks up the cycle change once you do a POST request to:

https://api.smartthings.com/v1/devices/DEVICEID/commands

The body of this post should contain:

[{
    "capability":"samsungce.washerCycle",
    "command":"setWasherCycle",
    "arguments":["Course_1D"]
}]

To change the cycle use the “Course_” prefix and then the code from the GET request (e.g. 1D, 1E, etc.)

Once you’ve got the request to work, you can create yet another line under the shell command section in your configuration.yaml and then use the new service in an automation or a button on the front end.

While it’s nice to see this work, I’m not sure how useful it is in practice since you already need to put the load into the machine and press the button to enable remote control. You may as well select the program then when you’re at the machine. I haven’t quite found a way to automatically put the dirty laundry in the machine form the washing basket, if only we could :slight_smile:

Valid point regarding the programme.

Think I will leave that for now.

Now I need to wait for the Growatt servers to start working in HA again so I can set the automation for when the solar is generating over 2kwh.

Thank you for your help, it is most appreciated.

Hi There,

It seems a lot of people are helping here, which is fine.
Am I correct that with this approach, I can keep everything in the LAN.
I would rather not open ports for IOT
Most of my IOT devices are on a seperate lan section lets say 192.168.44.0/24
Things inside this can’t go to the internet, but HA is installed on another lan section and can communicate with the devices in the IOT lan section.
This seem to work for my cameras and other devices.

But upon reading over the washer from samsung (so many posts) I’m not sure.
Thanks for reading and I hope somebody can clarify this…

From what I understand that is being discussed here, in the first x posts the subject is using the SmartThings integration. Then later, the subject changes to using custom switches and performing REST API calls to api.smartthings.com. That still uses the cloud service of Samsung.

I share your desire for local control and while not discussed here (yet? or it deserves a topic of its own), I assume that the cloud service sends some kind of command to the washer itself. Possibly, you could use a tool like WireShark to snoop on your network traffic and figure out what the actual commands sent to your washer are.
Keep in mind that the above contains a big IF, as I haven’t tried any of this for my Samsung devices.
Perhaps someone has some experience with this they could share?

P.S. I’m new here, looking to automate all the things in my home based on (solar) energy availability and price, as well as prioritization of appliances needing to run etc.

1 Like

I love this guide, thanks so much. I was able to easily implement it.

One question though: have you managed to actually resume a paused cycle? I can’t get this to work, since the start_cycle does not seem to work on a paused cycle.