Automating On when it is Off, periodically. My code will always give an error

I tried all methods but still failed. I pray to god, hopefully, someone knows a solution to this.

I get the error “422 The request is malformed. name: Unrecognized field “name” (class v20190122.internal.st.behaviors.Action), not marked as ignorable”

I want to check if it is ON every 1 hour and if it OFF then turn it ON. Even if it is not possible every 1 hour, then execute the same logic in the previous statement.

{
    "name": "Check and enable rapid cooling and freezing.",
    "actions": [
        {
            "if": {
                "and": [
                    {
                        "equals": {
                            "left": {
                                "device": {
                                    "devices": [
                                        "xxxxxx"
                                    ],
                                    "component": "main",
                                    "capability": "refrigeration",
                                    "attribute": "rapidCooling"
                                }
                            },
                            "right": {
                                "boolean": false
                            }
                        }
                    },
                    {
                        "equals": {
                            "left": {
                                "device": {
                                    "devices": [
                                        "xxxxx"
                                    ],
                                    "component": "main",
                                    "capability": "refrigeration",
                                    "attribute": "rapidFreezing"
                                }
                            },
                            "right": {
                                "boolean": false
                            }
                        }
                    }
                ]
            },
            "then": [
                {
                    "command": {
                        "devices": [
                            "xxxxx"
                        ],
                        "commands": [
                            {
                                "component": "main",
                                "capability": "refrigeration",
                                "command": "setRapidCooling",
                                "arguments": [true]
                            }
                        ]
                    }
                },
                {
                    "command": {
                        "devices": [
                            "xxxxxx"
                        ],
                        "commands": [
                            {
                                "component": "main",
                                "capability": "refrigeration",
                                "command": "setRapidFreezing",
                                "arguments": [true]
                            }
                        ]
                    }
                }
            ],
            "else": []
        }
    ]
}

How are you trying to add this code. If you are using the “New” advanced web app method, you do not include the name in the code and start at:
{
“if”: {
“and”: [

and I think you eliminate the last 2 lines

I am using “Samsung account

[
    {
        "if": {
            "and": [
                {
                    "equals": {
                        "left": {
                            "device": {
                                "devices": [
                                    "xxxxxxxxxxx"
                                ],
                                "component": "main",
                                "capability": "refrigeration",
                                "attribute": "rapidCooling"
                            }
                        },
                        "right": {
                            "boolean": false
                        }
                    }
                },
                {
                    "equals": {
                        "left": {
                            "device": {
                                "devices": [
                                    "xxxxxxxxxx"
                                ],
                                "component": "main",
                                "capability": "refrigeration",
                                "attribute": "rapidFreezing"
                            }
                        },
                        "right": {
                            "boolean": false
                        }
                    }
                }
            ]
        },
        "then": [
            {
                "command": {
                    "devices": [
                        "xxxxxxxxx"
                    ],
                    "commands": [
                        {
                            "component": "main",
                            "capability": "refrigeration",
                            "command": "setRapidCooling",
                            "arguments": [true]
                        }
                    ]
                }
            },
            {
                "command": {
                    "devices": [
                        "xxxxxxxx"
                    ],
                    "commands": [
                        {
                            "component": "main",
                            "capability": "refrigeration",
                            "command": "setRapidFreezing",
                            "arguments": [true]
                        }
                    ]
                }
            }
        ],
        "else": []
    }
]

Even with the above code, it gives the same error. Device ID is just redacted, of course I am using the right ID.

Sorry I couldn’t help

Actually the error is “422 The request is malformed. then: Unrecognized field “then” (class v20190122.internal.st.behaviors.Action), not marked as ignorable”

I used “on” instead of “true” because that’s what is listed under commands.

[
    {
        "if": {
            "and": [
                {
                    "equals": {
                        "left": {
                            "device": {
                                "devices": [
                                    "xxxxx"
                                ],
                                "component": "main",
                                "capability": "refrigeration",
                                "attribute": "rapidCooling"
                            }
                        },
                        "right": {
                            "boolean": false
                        }
                    }
                },
                {
                    "equals": {
                        "left": {
                            "device": {
                                "devices": [
                                    "xxxxx"
                                ],
                                "component": "main",
                                "capability": "refrigeration",
                                "attribute": "rapidFreezing"
                            }
                        },
                        "right": {
                            "boolean": false
                        }
                    }
                }
            ]
        },
        "then": [
            {
                "command": {
                    "devices": [
                        "xxxx"
                    ],
                    "commands": [
                        {
                            "component": "main",
                            "capability": "refrigeration",
                            "command": "setRapidCooling",
                            "arguments": ["on"]
                        }
                    ]
                }
            },
            {
                "command": {
                    "devices": [
                        "xxxx"
                    ],
                    "commands": [
                        {
                            "component": "main",
                            "capability": "refrigeration",
                            "command": "setRapidFreezing",
                            "arguments": ["on"]
                        }
                    ]
                }
            }
        ],
        "else": []
    }
]

under “setRapid…” it is “on” and “off”

Hi @nayelyz !, Can you please help me figure out a working code?

Hi @orangebucket ! , can you please help me figure out a working code? Any help is highly appreciated

The then and else should be properties of the if action.

"if": {
    "and": [ ... ],
    "then": [ ... ],
    "else": [ ... ]
}

I believe the command argument is probably going to need to be more like [ { "string": "on" } ] rather than just [ "on" ] as each argument is an object and the argument type has to be specified.

Hi, @mans!
Aside the comments from @orangebucket

I modified the conditions since the attributes of the capability refrigeration are String and can only be “on” or “off”. I tested it with a virtual device and it seems to be working correctly:

[
  {
    "if": {
      "and": [
        {
          "equals": {
            "left": {
              "device": {
                "devices": [
                  "xxxx"
                ],
                "component": "main",
                "capability": "refrigeration",
                "attribute": "rapidCooling"
              }
            },
            "right": {
              "string": "off"
            }
          }
        },
        {
          "equals": {
            "left": {
              "device": {
                "devices": [
                  "xxxx"
                ],
                "component": "main",
                "capability": "refrigeration",
                "attribute": "rapidFreezing"
              }
            },
            "right": {
              "string": "off"
            }
          }
        }
      ],
      "then": [
        {
          "command": {
            "devices": [
              "xxxx"
            ],
            "commands": [
              {
                "component": "main",
                "capability": "refrigeration",
                "command": "setRapidCooling",
                "arguments": [
                  {
                    "string": "on"
                  }
                ]
              }
            ]
          }
        },
        {
          "command": {
            "devices": [
              "xxxx"
            ],
            "commands": [
              {
                "component": "main",
                "capability": "refrigeration",
                "command": "setRapidFreezing",
                "arguments": [
                  {
                    "string": "on"
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  }
]

Another possible (different) approach to tackle the problem
Create virt switch v1

Trigger 1 if switch v1 on turn off (delay 1 hour)
Trigger 2 if switch v1 off turn on (delay 1 hour)
Trigger 3 if switch v on or off then take your custom action

Trigger 3 should run once every hour caused by change in state from trigger 1 or 2

In trigger 3 you can take whatever check and action you like

Using Rules API rule is possible to execute logic periodically using every action.

This example is executed every hour

{
  "name": "Every hour - Do something",
  "actions": [
        {
            "every": {
                "interval": {
                    "value": {
                        "integer": 1
                    },
                    "unit": "Hour"
                },
			  "actions": [
						{
						  "if": {
							"equals": {
							  "right": {
								"device": {
								  "devices": [
									"-- ID Virtual Switch 1 --"
								  ],
								  "component": "main",
								  "capability": "switch",
								  "attribute": "switch"
								}
							  },
							  "left": {
								"string": "off"
							  }
							},
							"then": [
							  {
								"command": {
								  "devices": [
									"-- ID Virtual Switch 2 --",
								  ],
								  "commands": [
									{
									  "component": "main",
									  "capability": "switch",
									  "command": "on"
									}
								  ]
								}
							  }
							]
						  }
						}
					]
	         }
	     }
	]
}

The routine is not executed in even hours. The routine is executed for the first time one hour after its creation.