Almost there, The only problem is the light level 'payload' needs to come in as msg.payload.light rather than just a number as I have it, then it can be filtered of in the function.
Good point on hysteresis, smoothing would soft that hopefully or a bracketed range <3 >5 soft of thing.
Dave.
[{"id":"6451506e.102dd","type":"sunpos","z":"940a6fc7.c59bf","name":"","lon":"-5","lat":"50.","start":"sunriseEnd","startoffset":0,"end":"sunsetStart","endoffset":0,"x":279,"y":353,"wires":[["33ad6f00.05b282","83e28cea.27666"]]},{"id":"ce605dfa.357ef","type":"debug","z":"940a6fc7.c59bf","name":"","active":true,"console":"false","complete":"true","x":515,"y":426,"wires":[]},{"id":"2f72955e.0e280a","type":"inject","z":"940a6fc7.c59bf","name":"","topic":"","payload":"3","payloadType":"num","repeat":"","crontab":"","once":false,"x":101,"y":453,"wires":[["eb6e1401.767408"]]},{"id":"c7bb17be.e9ae58","type":"mqtt in","z":"940a6fc7.c59bf","name":"","topic":"light","qos":"2","broker":"f2bcedec.c204e","x":81,"y":383,"wires":[["33ad6f00.05b282","6451506e.102dd"]]},{"id":"eb6e1401.767408","type":"mqtt out","z":"940a6fc7.c59bf","name":"","topic":"light","qos":"","retain":"","broker":"f2bcedec.c204e","x":222,"y":454,"wires":[]},{"id":"33ad6f00.05b282","type":"function","z":"940a6fc7.c59bf","name":"test with light at 3","func":"var altitude = msg.payload.altitude;\nvar light = 3\nif (altitude <4 && light <5)\n\n{msg.payload.lamp = 1;\n}else{\n msg.payload.lamp = 0;}\n \nreturn msg;\n","outputs":1,"noerr":0,"x":288,"y":407,"wires":[["ce605dfa.357ef"]]},{"id":"83e28cea.27666","type":"function","z":"940a6fc7.c59bf","name":"Sanity check","func":"if (msg.payload.altitude < 4){\n msg.payload.less = 1;\n}else{ msg.payload.less = 0;}\nreturn msg;","outputs":1,"noerr":0,"x":474,"y":344,"wires":[["b5dd636e.27d3c"]]},{"id":"b5dd636e.27d3c","type":"debug","z":"940a6fc7.c59bf","name":"","active":true,"console":"false","complete":"true","x":516,"y":389,"wires":[]},{"id":"f2bcedec.c204e","type":"mqtt-broker","z":"","broker":"192.168.1.40","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]