ragoth
Junior Member
Posts: 64
|
Post by ragoth on May 31, 2016 14:39:08 GMT
Hi, Some sensors like Gas, Fire etc., gives high analog output (1023) when there is no gas or fire exists and gives low analog output when it senses harmful gas or fire etc.,. Please advice how to reverse the reading displayed, like 1023 from sensor to show zero (or 0%)on and zero from sensor to show high 1023 (or 100%)on the openHab display. This will make the displayed reading proportionate to sensing element.
|
|
|
Post by greginkansas on May 31, 2016 22:48:48 GMT
Try the map command on the node
Some sensor = map(Some sensor,0, 1023, 1023, 0); //
|
|
|
Post by papa on Jun 1, 2016 0:22:38 GMT
Hmmm, Greg & ragoth, seems like using map() would require 1024 pairs of numbers in the parenthese. How about this that I adapted from here. Reading = analogRead(Pin);
// invert the reading from 0-1023 to 1023-0 InverseReading = 1023 - Reading; Thus subtracting the original reading from 1023 converts 1023 to 0, 0 to 1023, & should convert the values in between.
|
|
ragoth
Junior Member
Posts: 64
|
Post by ragoth on Jun 1, 2016 1:41:49 GMT
Sorry I missed to mention that I want to do it using item / rules code. In the Arduino node I am already using the map option to do similar role for dimmer function.
Please suggest me the rules / item code to achieve this.
|
|
|
Post by papa on Jun 1, 2016 4:57:28 GMT
Instead of trying to do this in an OpenHAB config file (item, rules),
it makes more sense to me to put it in the sketch of the node that has the sensor. Find the analogread() for the sensor & put the calculation (1023 - ) just after that.
This way the node will report the sensor state in the form you need.
|
|
|
Post by greginkansas on Jun 2, 2016 0:07:31 GMT
I use this for something like you want. But the only reason to do it this way so I only send the value once, use a js transform in a new item but using the same mqtt item. I will leave the code in your js file to you.
Number barometer_inHg_acurite_for_wall "Pressure inHg [%.0f]" (acurite) {mqtt="<[mosquitto:weather/weewx/barometer_inHg:state:JS(mult100.js)]" }
(mult100.js) file in the transtorm folder
(function(inHg) { return inHg * 100; })(input);
|
|