Is it possible to pass a variable to a tuya action (for instance a colour hue?) All questions

I would like to pass a colour hue value to the color_data (_v2 in some instances) so that I can use one sequence for all colour changes in my code (it will be a broadband throughput gauge). Red = over 75% bandwidth in use, yellow is over 50%, green its less than 50, off will be less than 10% or something like that. My code will trigger the web hook and perform the hue calculation for this one sequence to implement the change.

Thank you for your help

Asked by Rich on June 28, 2020, at 1:04pm

Hi Rich. When you refer to your code, do you mean the steps in the sequence or code which is hosted externally to SEQUEmatic?

Assuming this is code hosted elsewhere which will then trigger a webhook request, the answer is that you can reference variables passed from a webhook has parameters by enclosing their name in curly brackets. There is some information here in the docs.

Firstly, the way to name the parameters will depend on your webhook. You should read about the IFTTT webhook trigger and custom webhook trigger for more information. If you can tell me more about the webhook you're using (how does it pass the data - via the URL? as a POST request? is it JSON?) then I can give you more guidance on how to access the data in your sequence.

Once you have determined the correct webhook trigger, you can then access that value by enclosing it in curly brackets. For example, if you passed the current broadband consumption in a parameter named broadband_usage, you would access it as {broadband_usage} in your steps.  See below as an example where you can check if {broadband_usage} is greater than 50:

Hopefully these comments help to get you started, and if you can share some more information here I'll be able to provide more specific advice.

Hi Derek,

Thank you for the detailed answer, absolutely superb starting point. 

I see that there are two ways I can go from here. 

New idea:

If my original idea doesn't work, is it possible to have several check variable steps as an “or” condition?

Original (preferred) idea:

This is my originally (badly worded) question.... Using the Tuya step in a sequence, is it possible to pass a variable in to the JSON step. I tried to use a variable & alternatively a parameter but they don't appear to be passed through to the Tuya service the best I can tell. 

could this be because both square and curly brackets are used in JSON?

I hope that the question makes somewhat more sense. For understanding the source, I'll be making a webhook request from a raspberry pi I have looking at a Ubiquiti wireless bridge link between buildings. I already have that code ready to integrate and can see these are passed to your fantastic service.

Pseudo JSON I would like to be sent to Tuya smart bulb color_data_v2 {h:broadband_usage,s:1000,v:1000}

rather than set up multiple sequences for each colour I would like to use. 

Hi Rich, thanks for the additional information. Actually, I've gone back and reviewed the Tuya step and it currently doesn't accept variables or parameters in the JSON simply because I have not implemented it. Give me some time to work on this and it should be available soon.

Ok Rich, can you give this a go now? I don't have a Tuya device so unfortunatley can't test but if you can try it out and let me know if it works that would be great.

You should just be able to enclose a variable in square brackets or another sequence parameter in curly brackets like you would in other step types.

Hi Derek,

I have given it a whirl. My test sequence that didn't work yesterday now works perfectly.

Thank you for your help!

Also - I am 99% certain that the JSON specs for color_data_v2 should be: 

This is a JSON field. Specs are below.

H = Hue = Colour (Degrees 0 => 360)

S = Saturation = Shade (0 [off] -> 999 [on]) 

V = Value = Brightness (0 [off] -> 999 [on])

Excellent, thanks for confirming! Also thanks for sharing the details on the JSON. I'll add this in the docs as well.

Post a reply

The SEQUEmatic bot is still new and learning. If you don't get the answer you need, just ask to speak with Derek and your chat will be transferred.