Hi Everyone,
I am trying to create logic using the Function node where:
(1) peak times (3PM - 8PM), I assign and use one peak rate, a constant, that will be used as a factor
(2) non-peak times (outside of 3-8), would have a lower rate
I want to take the factor and multiple it by an instantaneous Energy reading (Watts), which I am able to pull from an HTTP request.
Here’s what I have within the function Node:
var peak = ‘0.32’
var nonpeak = ‘0.22’
var now = new Date();
var hour = now.getHours();
// var day = now.getDay();
// var minutes = now.getMinutes();
IF(hour > 15 || hour < 20)
msg.topic = peak;
else msg.topic = nonpeak;
return msg;
I’m not doing something right, because regardless of my logic, I keep getting the msg.topic = 0.32. In short, it looks like I am able to see the output with msg.topic = 0.32, but I am unable to apply the logic to evaluate the current time.
Any help would be appreciated.
Jon
Here’s the JSON export:
[{“id”:“c04b8dfd.7bc”,“type”:“function”,“z”:“c750655c.34e948”,“name”:“rate determine”,“func”:“var peak = ‘0.32’\nvar nonpeak = ‘0.22’\n\nvar now = new Date();\n var hour = now.getHours();\n// var day = now.getDay();\n// var minutes = now.getMinutes();\n IF(hour > 15 || hour < 20)\n msg.topic = peak; \n else msg.topic = nonpeak;\nreturn msg;”,“outputs”:1,“noerr”:3,“x”:410.5,“y”:393,“wires”:[[“e56a45be.a23d08”]]}]