# Power outage using card-voltage with twillio sms

**URL:** <https://discuss.blues.com/t/power-outage-using-card-voltage-with-twillio-sms/1453>\
**Category:** Uncategorized\
**Created:** [June 19, 2023, 11:42am UTC](https://discuss.blues.com/t/power-outage-using-card-voltage-with-twillio-sms/1453 "2023-06-19T11:42:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitecantropo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/pitecantropo/32/833_2.png) [@pitecantropo](https://discuss.blues.com/u/pitecantropo)\
**Post date:** [June 19, 2023, 11:42am UTC](https://discuss.blues.com/t/power-outage-using-card-voltage-with-twillio-sms/1453/1 "2023-06-19T11:42:35Z")

</div>

Hi, Im trying to set up a power outage similar to [Cellular-Enabled Power Outage Detector w/ SMS Notifications - Hackster.io](https://www.hackster.io/rob-lauer/cellular-enabled-power-outage-detector-w-sms-notifications-181408) but using the new card-voltage option.

I can seen both  
\_health.qo {“text”:“USB power OFF {usb-disabled}”}  
and  
\_health.qo {“text”:“USB power ON {usb-enabled}”}

events.

I have also \_health.qo to twillio and can receive sms when i populated the message filed with any field.

Cant seem to work out how to set the jsondata query in filter to receive in the msg body when the power is on/off depending on the condition.

Thanks in advance. any support is appreciated!

---

<div class="post-metadata">

**Author:** ![RobLauer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/roblauer/32/1567_2.png) [@RobLauer](https://discuss.blues.com/u/RobLauer)\
**Post date:** [June 19, 2023, 2:53pm UTC](https://discuss.blues.com/t/power-outage-using-card-voltage-with-twillio-sms/1453/2 "2023-06-19T14:53:22Z")

</div>

Hi @pitecantropo,

In your Twilio SMS route within Notehub, scroll to the bottom and you’ll see the **Transform Data** section. You can use a JSONata Expression to customize the SMS here:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/blues/original/1X/a7996656f39e9b29a81dfce1c93ed70bccf45944.png)

This is the expression that I’ve been using (from our [accelerator app](https://dev.blues.io/accelerators/power-outage-detection/)):

```auto
(
    $alertMessage := function($e, $nodeID) {(
        $texts := [
            {"text":"USB power OFF", "msg":"ALERT! Power has failed to device "},
            {"text":"USB power ON", "msg":"Power restored to device "},
            {"text":"brown-out", "msg":"Power restored (LiPo battery discharged) to device "}
        ];
        $findPowerStatus := function($text, $index) <sn:s> {(
            $index >= $count($texts) ? "" :
                $contains($text, $texts[$index].text) ? $texts[$index].msg : $findPowerStatus($text, $index+1);
        )};
        $msg := $findPowerStatus($.body.text, 0);
        $result := $msg ? { "customMessage": $msg & $.best_id & "."} : {};
    )};
    $additional := $alertMessage($);
    $additional.customMessage ? $merge([$, {"body": $merge([body, $additional])}]) : $doNotRoute($);
)

```

---

<div class="post-metadata">

**Author:** ![pitecantropo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/pitecantropo/32/833_2.png) [@pitecantropo](https://discuss.blues.com/u/pitecantropo)\
**Post date:** [June 19, 2023, 3:12pm UTC](https://discuss.blues.com/t/power-outage-using-card-voltage-with-twillio-sms/1453/3 "2023-06-19T15:12:41Z")

</div>

Hi Rob,

Thanks.  
Would the “Message” input in twillio settings be left blank?

![image](https://us1.discourse-cdn.com/flex020/uploads/blues/original/1X/48432f37e9c8a5b5d3a9551679a6b5d08e8a0614.png)

I find that if I leave it blank

get the following error:  
error building route request: error validating twilio message: %!w(), got that also from the expression you shared.

---

<div class="post-metadata">

**Author:** ![pitecantropo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/pitecantropo/32/833_2.png) [@pitecantropo](https://discuss.blues.com/u/pitecantropo)\
**Post date:** [June 19, 2023, 3:38pm UTC](https://discuss.blues.com/t/power-outage-using-card-voltage-with-twillio-sms/1453/4 "2023-06-19T15:38:49Z")

</div>

Sorry. Just understood.

added [.body.customMessage] the message guide and can now see both loss and restore sms!!!

Thanks again for your time and patience : )
