Filtering a number value in a string

Using the alexa.remote2 palette, when asking alexa, for example, "Whats the current temperature?"
This is the response i get in the debug
image
How do i use a switch node to use like "is between" two values when the answer is in a string??

I can use contains, like this, but i would need alot of outputs to cover a wide temp range
image

just cant seem to find a way
cheers

Quick and dirty way :slight_smile:

image

[{"id":"25d8f339c39a9601","type":"inject","z":"e65ad62fea9fb3f4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Right now, it's 6 degrees Celsius.","payloadType":"str","x":100,"y":1350,"wires":[["3f11c4c89fadca94"]]},{"id":"3f11c4c89fadca94","type":"split","z":"e65ad62fea9fb3f4","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":230,"y":1350,"wires":[["01b0444ce0f8c06a"]]},{"id":"01b0444ce0f8c06a","type":"switch","z":"e65ad62fea9fb3f4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"-100","vt":"num","v2":"100","v2t":"num"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":1350,"wires":[["aa94bb951f8eb1ef"]]},{"id":"aa94bb951f8eb1ef","type":"debug","z":"e65ad62fea9fb3f4","name":"debug 398","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":1350,"wires":[]}]

split by " "


check if in a range
image

Note - sometimes Alexa can go off on a tangent so other sanity checks would be needed :slight_smile:

2 Likes

Thanks...

True about Alexa... I can sort out her tangents in other ways...

you can also use a Jsonata with a regular expression to pick the number out of the string
$match(payload.alexaResponse, /\d\d?/)

Test Flow

[{"id":"6a18ea68e6e856fd","type":"inject","z":"54efb553244c241f","name":"alexaResponse 23","props":[{"p":"payload.alexaResponse","v":"Right now, it's 23 degrees Celsius","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":3900,"wires":[["8998cf9da4e6531c"]]},{"id":"8998cf9da4e6531c","type":"change","z":"54efb553244c241f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$match(payload.alexaResponse, /\\d\\d?/)","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$number(payload.match)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":3940,"wires":[["b23ac979c073ab52"]]},{"id":"b23ac979c073ab52","type":"debug","z":"54efb553244c241f","name":"debug 62","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":3940,"wires":[]},{"id":"676c3c1aab72c28f","type":"inject","z":"54efb553244c241f","name":"alexaResponse 9","props":[{"p":"payload.alexaResponse","v":"Right now, it's 9 degrees Celsius","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":200,"y":3980,"wires":[["8998cf9da4e6531c"]]}]
1 Like

Thanks aswell

Most appreciated both of you

Cheers