Help with Alexa+Node Red+Blynk

Hello friends. Im totally new on IOT but im discovering it and trying to build some things. I have no experience on programming, but until now, i managed to overcome my problems.
So, i have a blynk local server+node red+mosquitto running on a pi zero. Also i have a esp8266 measuring temp/humidity to the local server and monitoring it on blynk android app.
What i want to do is, through Alexa, ask what is the temperature of… and manage to have a reply. Im trying to build a Flow on node red but i cant have it to work.
I use Node-RED Alexa Home Skill Bridge by hardill.
I linked Alexa to V0 pin of my Blynk project, Alexa request but answer of that device is not responding. I thing this is a build problem cause on debug messages i see a response from blynk server but nothing on Alexa link.
Sorry for my english.Not my mother language.
Cheers

My advice would be not to run any Blynk code on your device. Only run MQTT code that pushes the temperature reading into Node-Red (and subscribes to topics if you want to be able to control the device through MQTT commands).

If you want to skip this stage then simply assign a value to a variable in Node-Red and query this value via Alexa.
In your home skill Bridge device setup you must have the “query current temp” checkbox selected as well as °C/F.
If you make any changes then do an “Alexa discover new devices” to update Alexa’s skill set for the device.

If I get chance later I’ll do a quick demo flow.

Pete.

1 Like

Thank your for your reply.
Yes i have “Query current temp” selected in my skill bridge device. I choose this method of using Blynk nodes directly because i use Blynk app alot, but, if with MQTT commands is better, i can try putting the code on my sketch. I think it won’t be much problem. But, if i can manage to work with Alexa directly using Blynk nodes, it would be great.

Okay, take a look at this flow…

The top row gets the value from a temperature sensor in my living room and stores it in a flow level variable called “Temperature”. This value is updated every 5 seconds by the MCU connected to the sensor. In this case, the temperature data is sent to Node-Red as an MQTT message, because that’s how I do it. You could just as easily be getting the temperature sent to Node-Red via a Blynk Write node.

I’m saving the temperature reading to a variable because I need to use it in the ‘Get data for response function’ below.

The second row has an Alexa Home device set-up as we discussed earlier, and called Living Room. The Auto Acknowledge checkbox needs to have the tick removed.

The function contains the following code…

var Temperature = flow.get('Temperature');

msg.extra = {
    "temperatureReading": {
        "value": Temperature
    },
    "applianceResponseTimestamp": new Date().toISOString()
};
msg.payload = true;
return msg; 

The first line of code retrieves the latest value from the level variable called ‘Temperature’ and makes it available as a function level variable also called ‘Temperature’.

The rest of the code is taken from the ‘GetTemperatureReadingRequest’ example here:

https://alexa-node-red.bm.hardill.me.uk/docs

but instead of using a hard-coded temperature of 21.11 degrees in the example:

msg.extra = {
    "temperatureReading": {
        "value": 21.11

I’ve used the value of the ‘Temperature’ variable…

msg.extra = {
    "temperatureReading": {
        "value": Temperature

Now, when I say “Alexa, what’s the living room temperature” the response is “The living room temperature is 25.6 degrees”

Pete.

Thanks!
So in first row, those sensor values are coming from MQTT right?

In this example yes. As I said, I don’t run any Blynk code on my devices, the Blynk integration is done in MQTT with my setup.

However, the principal is very similar. Every 5 seconds my device takes a temperature reading from the sensor and pushes it to Node-Red via an MQTT message.
In your case I guess you’re pushing these readings to a Blynk server on a virtual pin and you’re getting that into Node-Red via a Blynk Write node.
Either way, provided the data is getting into Node-Red you can store it in a variable and use it in the second row if the flow.

Pete.

I wil try…

Have you seen my Node-Red/MQTT topic…

Pete.

I will see it for sure

Hello again. I’ve done it. After some problems i managed to solved it

Thanks Pete. I couldn’t do it without your help

That doesn’t look the way I expected it to.
What type of node is the one labelled “V0 - Temperature”.

Pete.

chrome_v7rkATLG7j

The “read” one. It connects to Virtual Pin 0 and outputs value when triggered…

Okay.
The node-red-contrib-blynk-api contrib that you’re using isn’t one I’ve seen before. I’d recommend that you stop using it and switch to the node-red-contrib-blynk-ws contrib, as it’s much more powerful, because it uses websockets to communicate with the Blynk server rather than API calls.

Pete.

Thanks. Switched already…

1 Like

Strange thing happened now. Blynk app is Ok, but when i ask temperature to Alexa, the answer is 0º. Already restarted blynk server, node red and ESP and problem remains… It was working very well untill now

What does your updated flow look like now that you’ve changed to the WS contrib?

Pete.

Now its stucked on 25º. Every query, Alexa responds 25. Real temp is higher on Blynk app

Edit: If i delete and put again the switch function, value will update but stucks on the first sample…
Maybe is a node red issue cause this was working flawlessly

Well i think i solved it… for now… I discovered that activity on Blynk Vpin must be triggered. If not it will send only first value when its deployed the first time. I used this solution, a 10 sec timestamp trigger. It triggers output of value and refresh the output.

But you’re still using the Blynk API contrib node.

Your sketch on the device should be writing the temperature to pin V0 using a timer (say every 5-10 seconds) and you should have a Blynk Write node picking-up these values and saving them to your flow level variable as was happening in my example with the incoming MQTT values.

Pete.