IoT Hub - Power Apps Control External Device

Ying Min Teo 1 Reputation point
2022-07-05T15:30:13.767+00:00

Hi,

Is it possible to control external device (e.g.: a lock) by connecting Power Apps and IoT Hub?
I want to use Power Apps to control open/close a safety box lock. Possible to connect Power Apps and IoT Hub together?
Or is there any better solution for this?

Thanks.

Azure IoT Central
Azure IoT Central
An Azure hosted internet of things (IoT) application platform.
365 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,218 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 35,171 Reputation points
    2022-07-08T15:44:20.713+00:00

    @Ying Min Teo Please check the Unlock the Future of Azure IoT through Power Platform to understand how to use IoT hub and Power Apps to control an IoT device.

    You need to write a code (Ex. Node for IoT Hub) in Azure IoT Hub, to send commands directly to your IoT device and then create a flow in Power Automate, and connect that flow to a Power App, which will be a complete dashboard that controls the IoT device from anywhere in the world.

    Hope this helps. Do let us know if you have any further queries.

    If the response is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

  2. QuantumCache 20,346 Reputation points
    2022-10-21T03:36:46.483+00:00

    Hello @Ying Min Teo ,

    Adding to the above response posted by AshokPeddakotla-MSFT.

    As suggested by Ashok in the above response, please try to use the Power Apps flow and make use of the Azure IoThub REST API to call the direct methods on the IoT Device.

    252833-image.png

    252784-image.png

    Cloud-to-device communications guidance

    IoT Hub provides three options for device apps to expose functionality to a back-end app:

    • Direct methods for communications that require immediate confirmation of the result. Direct methods are often used for interactive control of devices such as turning on a fan.
    • Twin's desired properties for long-running commands intended to put the device into a certain desired state. For example, set the telemetry send interval to 30 minutes.
    • Cloud-to-device messages for one-way notifications to the device app.

    IoT Hub gives you the ability to invoke direct methods on devices from the cloud. Direct methods represent a request-reply interaction with a device similar to an HTTP call in that they succeed or fail immediately (after a user-specified timeout). This approach is useful for scenarios where the course of immediate action is different depending on whether the device was able to respond.

    Direct methods are implemented on the device and may require zero or more inputs in the method payload to correctly instantiate.

    Invoke a direct method from a back-end app

    To invoke a direct method from a back-end app use the Invoke device method REST API or its equivalent in one of the IoT Hub service SDKs.

    Method invocation
    Direct method invocations on a device are HTTPS calls that are made up of the following items:

    The request URI specific to the device along with the API version:

    https://fully-qualified-iothubname.azure-devices.net/twins/{deviceId}/methods?api-version=2021-04-12  
    

    The POST method

    Headers that contain the authorization, content type, and content encoding.

    A transparent JSON body in the following format:

    {  
        "connectTimeoutInSeconds": 200,  
        "methodName": "reboot",  
        "responseTimeoutInSeconds": 200,  
        "payload": {  
            "input1": "someInput",  
            "input2": "anotherInput"  
        }  
    }  
    

    252815-image.png

    If the response is helpful, please click "Accept Answer" and upvote it. So that we can close this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.