AND Logic not operating

Hi all,

I'm after some help with a AND logic function

The gate is not behaving like a AND gate and will pass with only one input active.

Any thoughts?

[{"id":"ed49abd7.bc8c18","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"bc3da4ff.eb3008","type":"api-call-service","z":"ed49abd7.bc8c18","name":"Rear Flood On","server":"b9e13121.b341a","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.sonoff_rearfloodlight","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1400,"y":480,"wires":[[]],"icon":"node-red-contrib-actionflows/actionflows.png"},{"id":"a8c64dff.556ef","type":"api-call-service","z":"ed49abd7.bc8c18","name":"Rear Flood Off","server":"b9e13121.b341a","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.sonoff_rearfloodlight","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1400,"y":580,"wires":[[]],"icon":"node-red-contrib-actionflows/actionflows.png"},{"id":"8ed31334.c30db","type":"trigger-state","z":"ed49abd7.bc8c18","name":"Intruder Alarm Trigger","server":"b9e13121.b341a","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"switch.sonoff_intruderalarm","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":240,"y":580,"wires":[["bf637c58.48fce"],[]]},{"id":"f1debdaf.a601d","type":"bigtimer","z":"ed49abd7.bc8c18","outtopic":"","outpayload1":"on","outpayload2":"off","name":"Big Timer","comment":"","lat":"53.30","lon":"2.24","starttime":"1215","endtime":"1245","starttime2":"1260","endtime2":"1410","startoff":0,"endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"on","outtext2":"off","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"day7":0,"month7":0,"day8":0,"month8":0,"day9":0,"month9":0,"day10":0,"month10":0,"day11":0,"month11":0,"day12":0,"month12":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"repeat":false,"atstart":true,"odd":false,"even":false,"x":500,"y":400,"wires":[["bf637c58.48fce"],[],[]]},{"id":"d1ecee5.19a0b1","type":"inject","z":"ed49abd7.bc8c18","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":360,"wires":[["f1debdaf.a601d"]]},{"id":"b2585a9f.58e418","type":"inject","z":"ed49abd7.bc8c18","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":440,"wires":[["f1debdaf.a601d"]]},{"id":"bf637c58.48fce","type":"and-gate","z":"ed49abd7.bc8c18","name":"","rules":[{"t":"eq","v":"on","vt":"str","propertyType":"msg","property":"payload","topic":""},{"t":"eq","v":"on","vt":"str","propertyType":"msg","property":"payload","topic":""}],"outputTopic":"","gateType":"and","emitOnlyIfTrue":false,"x":760,"y":480,"wires":[["5de57ca2.5ed424"]]},{"id":"5de57ca2.5ed424","type":"switch","z":"ed49abd7.bc8c18","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1030,"y":540,"wires":[["bc3da4ff.eb3008"],["a8c64dff.556ef"]]},{"id":"b9e13121.b341a","type":"server","z":"","name":"Home Assistant","addon":true}]

[edit]``` added around code[/edit]

Hi and welcone to NR forum.

couple of things here...

  1. in order to make code more readable an importable it is important to post it between two sets of three backticks - ``` - see this post for more details - How to share code or flow json

then please edit your code

  1. you cannot perform AND logic like that (due to mesages arriving into the "and gate" at different times

See this article in the cookbook for an example of how to join messages into one object.

Then you'll be able to perform the AND logic.

That's for the logic gates irrelevant, you can send different message with different time interval, it doesn't matter when the messages arrive. There can be days between them.
The input message topic combined with payload determines the setting or resetting from the input buffer.

[{"id":"3a514833.85a2c","type":"and-gate","z":"c07375d6.abd348","name":"","rules":[{"t":"true","propertyType":"msg","property":"payload","topic":"a"},{"t":"true","propertyType":"msg","property":"payload","topic":"b"}],"outputTopic":"OuTopic","gateType":"and","emitOnlyIfTrue":true,"x":440,"y":200,"wires":[["4d07fbed.191c0c"]]},{"id":"4d07fbed.191c0c","type":"debug","z":"c07375d6.abd348","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":200,"wires":[]},{"id":"ded2b00a.54cba8","type":"inject","z":"c07375d6.abd348","name":"","topic":"a","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":140,"wires":[["3a514833.85a2c"]]},{"id":"58cff7ec.28cb","type":"inject","z":"c07375d6.abd348","name":"","topic":"b","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":280,"wires":[["3a514833.85a2c"]]},{"id":"8a41df48.dac46","type":"inject","z":"c07375d6.abd348","name":"","topic":"a","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":180,"wires":[["3a514833.85a2c"]]},{"id":"bb621c20.674148","type":"inject","z":"c07375d6.abd348","name":"","topic":"b","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":320,"wires":[["3a514833.85a2c"]]}]

I think TS has to set the check box True restriction, but without importable code we can't check that.

I didnt import the flow either (due to not being importable) - but i see the subtle difference now (that node labelled "and gate" ISNT actually a switch node - its a shade different but otherwise identical!)

I dont use the logic gates (I pretty much use built in nodes for AND/OR logic)

did you read the info tab for the node?
Screen Shot 2020-06-06 at 5.18.41 PM

Hi Guys

Thanks for the responses, I do apologise if i sound a bit green, I'm a newbie and only been playing with Node red for a few days.

I want the Intruder alarm trigger only to operate the flood light after a set time.

So with my flow, what do I exactly need to do to fix it?

I've attached the code correctly below, I think

[{"id":"ed49abd7.bc8c18","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"bc3da4ff.eb3008","type":"api-call-service","z":"ed49abd7.bc8c18","name":"Rear Flood On","server":"b9e13121.b341a","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.sonoff_rearfloodlight","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1400,"y":480,"wires":[[]],"icon":"node-red-contrib-actionflows/actionflows.png"},{"id":"a8c64dff.556ef","type":"api-call-service","z":"ed49abd7.bc8c18","name":"Rear Flood Off","server":"b9e13121.b341a","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.sonoff_rearfloodlight","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1400,"y":580,"wires":[[]],"icon":"node-red-contrib-actionflows/actionflows.png"},{"id":"8ed31334.c30db","type":"trigger-state","z":"ed49abd7.bc8c18","name":"Intruder Alarm Trigger","server":"b9e13121.b341a","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"switch.sonoff_intruderalarm","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":240,"y":580,"wires":[["bf637c58.48fce"],[]]},{"id":"f1debdaf.a601d","type":"bigtimer","z":"ed49abd7.bc8c18","outtopic":"","outpayload1":"on","outpayload2":"off","name":"Big Timer","comment":"","lat":"53.30","lon":"2.24","starttime":"1215","endtime":"1245","starttime2":"1260","endtime2":"1410","startoff":0,"endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"on","outtext2":"off","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"day7":0,"month7":0,"day8":0,"month8":0,"day9":0,"month9":0,"day10":0,"month10":0,"day11":0,"month11":0,"day12":0,"month12":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"repeat":false,"atstart":true,"odd":false,"even":false,"x":500,"y":400,"wires":[["bf637c58.48fce"],[],[]]},{"id":"d1ecee5.19a0b1","type":"inject","z":"ed49abd7.bc8c18","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":360,"wires":[["f1debdaf.a601d"]]},{"id":"b2585a9f.58e418","type":"inject","z":"ed49abd7.bc8c18","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":440,"wires":[["f1debdaf.a601d"]]},{"id":"bf637c58.48fce","type":"and-gate","z":"ed49abd7.bc8c18","name":"","rules":[{"t":"eq","v":"on","vt":"str","propertyType":"msg","property":"payload","topic":""},{"t":"eq","v":"on","vt":"str","propertyType":"msg","property":"payload","topic":""}],"outputTopic":"","gateType":"and","emitOnlyIfTrue":false,"x":760,"y":480,"wires":[["5de57ca2.5ed424"]]},{"id":"5de57ca2.5ed424","type":"switch","z":"ed49abd7.bc8c18","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1030,"y":540,"wires":[["bc3da4ff.eb3008"],["a8c64dff.556ef"]]},{"id":"b9e13121.b341a","type":"server","z":"","name":"Home Assistant","addon":true}]

Thanks

Have you tried the delay node?

So after looking at your flow & reading your description - is this what you want?

  • IF time is in range (20:15 ~ 20:45 OR 21:00 ~ 23:30) ...
    • IF alarm trigger "on"
      • send "on" signal to rear flood light
    • IF alarm trigger "off"
      • send "off" signal to rear flood light
  • IF time is outside the range...
    • ignore the alarm signal

Question: Do you want the rear flood light to be sent an "off" when time reaches 20:45 and 23:30? (otherwise the alarm "off" would be ignored and the flood light would remain on all night)

OK, so I made some assumptions based on what seems sensible.

This is what I did...

the flow....

[{"id":"aad42814.760ec8","type":"inject","z":"6578e068.afc95","name":"fake schedule : on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"schedule","payload":"on","payloadType":"str","x":270,"y":400,"wires":[["f6c98c43.77ecd"]]},{"id":"5c22ab78.4c0ed4","type":"switch","z":"6578e068.afc95","name":"alarm: on? off?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":740,"y":280,"wires":[["45993978.5c92f8"],["fd812f17.f7756"]],"outputLabels":["on","off"]},{"id":"5f10d768.993f68","type":"cronplus","z":"6578e068.afc95","name":"","outputField":"payload","timeZone":"","commandResponseMsgOutput":"output1","outputs":1,"options":[{"expressionType":"cron","name":"schedule1","topic":"schedule","payload":"on","type":"str","expression":"0 15 20 * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"expressionType":"cron","name":"schedule2","topic":"schedule","payload":"off","type":"str","expression":"0 45 20 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"expressionType":"cron","name":"schedule3","topic":"schedule","payload":"on","type":"str","expression":"0 0 21 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"expressionType":"cron","name":"schedule4","topic":"schedule","payload":"off","type":"str","expression":"0 30 23 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":240,"y":480,"wires":[["f6c98c43.77ecd"]]},{"id":"15b0249f.1d28eb","type":"inject","z":"6578e068.afc95","name":"fake alarm trigger on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"alarm","payload":"on","payloadType":"str","x":270,"y":280,"wires":[["f8096d35.43a29"]]},{"id":"e50338cf.4ad818","type":"inject","z":"6578e068.afc95","name":"fake alarm trigger off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"alarm","payload":"off","payloadType":"str","x":270,"y":320,"wires":[["f8096d35.43a29"]]},{"id":"cf2c8ad1.f76168","type":"inject","z":"6578e068.afc95","name":"fake schedule : off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"schedule","payload":"off","payloadType":"str","x":270,"y":440,"wires":[["f6c98c43.77ecd"]]},{"id":"f8096d35.43a29","type":"switch","z":"6578e068.afc95","name":"schedule: on? off?","property":"schedule","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":280,"wires":[["5c22ab78.4c0ed4","57554d4e.177e14"],["57554d4e.177e14","fd812f17.f7756"]]},{"id":"57554d4e.177e14","type":"debug","z":"6578e068.afc95","name":"debug","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":550,"y":340,"wires":[]},{"id":"b460270d.afe888","type":"debug","z":"6578e068.afc95","name":"debug","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":550,"y":500,"wires":[]},{"id":"f6c98c43.77ecd","type":"change","z":"6578e068.afc95","name":"","rules":[{"t":"set","p":"schedule","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":440,"wires":[["b460270d.afe888","978428b2.0a3e68"]]},{"id":"45993978.5c92f8","type":"change","z":"6578e068.afc95","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":895,"y":280,"wires":[["de361641.9ec138"]],"l":false},{"id":"fd812f17.f7756","type":"change","z":"6578e068.afc95","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":895,"y":400,"wires":[["de361641.9ec138"]],"l":false},{"id":"978428b2.0a3e68","type":"switch","z":"6578e068.afc95","name":"off time?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":720,"y":440,"wires":[["fd812f17.f7756"]],"outputLabels":["off"]},{"id":"de361641.9ec138","type":"debug","z":"6578e068.afc95","name":"rear flood off / on","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1030,"y":340,"wires":[]}]

NOTES:

  • I did originally use a join node but it didn't quite work the way expected in this instance.
  • I didn't use the big timer (I don't have it & don't need it) - this example uses node-red-contrib-cron-plus. This has the advantage of having as many schedules as you need (this example is set for 2 "on" and 2 "off" times as per your original - but you can have pretty much unlimited schedules with almost infinite possibilities)

HI Steve-Mci

Sorry for the confusion, i was just playing around with the time settings.
There should only be one time range in the timer block.

The flood would only come on if the intruder alarm was triggered during the on period (i.e. night time).

thats fine.

The flow I posted works for that scenario - just change the CRON node

Thanks, I'll give it a try.

Hi Steve-Mci

It's working!!

Much appreciated and thanks for you help.

However is it possible to swap out the CRON + scheduler for the Big Timer?

I only ask as i had a thought that by setting it to activate at sunset then it would track throughout the year instead of having to constantly change the time schedule manually.

Just tried it with the big timer and it works.

Thanks again

Yes you can I'm certain but I don't use it or have it.

If you can wait a few days, the CRON node is to be updated to include any solar time you wish

I'm not in a rush, will leave the Big Timer in for now and give the CRON+ a try in a few days.

Thanks