virtualWrite will not cause trigger using MQTT


#1

I am using a Sparkfun 8266 Thing board with a PIR sensor. I am using the CayenneMQTT8266 library. I can configure a custom widget to display the results of a virtualWrite, but I cannot get a trigger to function from that virtualWrite value. If I instead use a luxWrite the trigger will work, but then I can’t get rid of the unit display (“lux”).

i.e. virtualWrite(2, digitalRead(4)); -> displays correctly but will not trigger
luxWrite(2, digitalRead(4)); -> will display and trigger

  trigger is configured as sensor above 0

I noticed that there are virtualWrite overloads that allow you to set Type and Unit

e.g. Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
Is there an equivalent for a digital sensor Type?

Thanks,
Ralph


#2

When you say you’re looking for a digital do you mean 0/1 values or as a replacement for the lux sensor?


#3

Yes, just 0/1 values, I just want to be able to add a digital sensor (PIR via digitalRead of GPIO) using MQTT to the Dashboard that would also trigger a response.

  1. If I add a custom widget manually it doesn’t respond to the state change.

  2. If I use the widget that Cayenne creates automatically when a virtualWrite is added in the code then it displays the value change but won’t trigger on the change. And this widget indicates that it is an analogSensor.

  3. If I use the widget that Cayenne creates automatically when a luxWrite is added in the code then it displays the value change and also triggers on the change. This widget is also an analogSensor and I set the trigger up identically to #2. Not sure what is magic about the luxWrite.

I was just wondering if there was a method to create a digitalSensor via adding a virtualWrite in the code.


#4

Yep, you can use the Digital Sensor type. Here is a list of all the types: Data types for Cayenne MQTT API


#5

Thanks for the link.

The vitualWrite does indeed create the DigitalSensor widget now.

I am still having a problem where the new widget won’t cause a trigger.

Here is how the 2 triggers are set up. The top works and the bottom doesn’t.

The top uses the widget generated by luxWrite(2, valPIR) and the bottom with virtualWrite(1, valPIR, “digital_sensor”, “d”).

int valPIR =digitalRead(4);


#6

Unfortunately there are some known issues with triggers right now. Tagging @rsiegel and @bestes so they know as well.