my idea is to receive a value over MQTT or HTTP request and write this value to a virtual Device or variable.
In case of MQTT there is a tag “message received from topic”, but this tag is only available for comparison/Logic in the AND flow. I see no possibilities to use the value that is in the message Tag to use it in the THEN flow.
I think the main reason will be, that the message is a STRING and it has to be converted to a number before it can be used for a “set value”.
Are there any other possibilities to receive values from outside and use this values in homey flows?
I am trying to do the same thing but from my weatherstation.
But I have never used homeyscripts and get a error message trying this script.
The value look like this:
{ 17.9 }
The script I wrote looks like this:
var MyNum = parseFloat(args[0])
await setTagValue(“RetNum”, { “number” }, MyNum);
return true;
I’ll have to defer to people that know more about flows under v2 than I do. But a few potential problems come to mind:
THEN cards are not executed one-after-the-other, but all at the same time. So while your script it still running (card #1), the value of the sensor is already been set (card #v2)
Instead of using a tag “Temperature”, use the string “Temperature”
Thanks for your answers.
In the code below what does RetNum come from? var MyNum = parseFloat(args[0]) await setTagValue("RetNum", {type: "number", title: "RetNum"}, MyNum); return true;
Sorry for more stupid questions.
MyNum is that then the name of the “value” that comes from my MQTT server ?
The topic from MQTT is WeatherDisplay/temp and the “value” looks like this { 18.0 }
MyNum is a JavaScript variable that you are assigning (through args[0]) the value from the MQTT topic. Is that value a string? If so, you first need to parse out the numerical value from it, you can’t use parseFloat on such a string directly.
Perhaps the flow editor shows it in a strange order. The “Sensor” should be measure_temperature and the “Value” should be the tag.
Also, it looks like you’re using the unofficial dashboard. I don’t know it that will show these devices properly. It’s better to check https://developer.athom.com/tools/devices to see the capabilities of the device.
OK, then its correct right now.
The dashboard picks the measure_temperature tag
Even in the Homey app the “Testmqtt” virtual device doesnt show any values.
In that case, there’s a big chance that showing sensor values for virtual devices just isn’t supported. Perhaps @DaneedeKruyff can comment on that with regard to the dashboard?
But even in Athoms Homey app it dont show values
And if I look at the device in http://developer.athom.com/ it says null
So I am probaly doing something wrong when I cant even get the test for updating sensor values right.