OK, this is odd. Here’s my function:
old_state = msg.data.old_state.state;
new_state = msg.data.new_state.state;
old_status = msg.data.old_state.attributes.lock_status;
new_status = msg.data.new_state.attributes.lock_status;
old_time = msg.data.old_state.last_changed;
new_time = msg.data.new_state.last_changed;
new_time_local = new Date(new_time);
textMessage = "The front door deadbolt changed state.\n";
textMessage += " Old state: "
textMessage += old_state;
textMessage += " - ";
textMessage += old_status;
textMessage += "\n\n";
textMessage += " New state: "
textMessage += new_state;
textMessage += " - ";
textMessage += new_status;
textMessage += "\n\n";
textMessage += "Date/time: ";
textMessage += new_time_local;
msg.textMessage = textMessage;
msg.textMessage2 = "Test message 2.";
return msg;
If I send textMessage2 to Twilio, the text message is sent and received by my phone. If I send textMessage, I get:
"Call-service API error. Error Message: extra keys not allowed @ data['0']"
Per the debug node, the msg object (after going through a JSON pretty-printer) is:
{
"topic": "<reallyLongDeviceName>",
"payload": "locked",
"data": {
"entity_id": "<reallyLongDeviceName>",
"old_state": {
"entity_id": "<reallyLongDeviceName>",
"state": "unlocked",
"attributes": {
"node_id": 6,
"value_index": 0,
"value_instance": 1,
"value_id": "<redacted>",
"notification": "Manual Lock",
"lock_status": "Manually Locked by Key Cylinder or Inside thumb turn",
"friendly_name": "<friendlyName>"
},
"last_changed": "2020-04-29T01:14:33.032447+00:00",
"last_updated": "2020-04-29T01:14:33.032447+00:00",
"context": {
"id": "<redacted>",
"parent_id": null,
"user_id": "<redacted>"
}
},
"new_state": {
"entity_id": "<reallyLongDeviceName>",
"state": "locked",
"attributes": {
"node_id": 6,
"value_index": 0,
"value_instance": 1,
"value_id": "<redacted>",
"notification": "Manual Lock",
"lock_status": "Manually Locked by Key Cylinder or Inside thumb turn",
"friendly_name": "<friendlyName>"
},
"last_changed": "2020-04-29T01:16:48.925835+00:00",
"last_updated": "2020-04-29T01:16:48.925835+00:00",
"context": {
"id": "<redacted>",
"parent_id": null,
"user_id": "<redacted>"
},
"timeSinceChangedMs": 55
}
},
"_msgid": "38ff9f0.dc16862",
"textMessage": "The front door deadbolt changed state.\n Old state: unlocked - Manually Locked by Key Cylinder or Inside thumb turn\n\n New state: locked - Manually Locked by Key Cylinder or Inside thumb turn\n\nDate/time: Tue Apr 28 2020 20:16:48 GMT-0500 (Central Daylight Time)",
"textMessage2": "Test message 2."
}
So what’s wrong with my textMessage string that the Twilio SMS sender thingy doesn’t like it?