Door sensor in node-red shall stop temperature check for 15 min

Hi,

I’m looking for the best way to integrate my aqara door sensor into the node-red flow below. The door sensor shall stop temperature polling (poll-state) for 15 minutes to prevent the start of the heating, when the door is opened.
What is the best way to do this?

Is the call service turn on the heating?
I don’t really understand what I’m looking at.

switch:turn_on will start the heating, yes.

Any specific reason why you are actively polling the sensor? Is it not sending state updates when changed?
Is sensor.flur your aquara door sensor? Or a different sensor?

Baiscally, you want the heating to turn on if the temperature falls below a specific threshold, but only if the door is closed correct?
You could then just use a wait node, and add that in between the action and the trigger.

I started with events state, but this will fire only, when the temperature is changing. As I want to start the heating at 06:00, sometimes the next stat changed triggered the start many minutes later. That’s why I tried to use poll state.
sensor.flur is an aqara sensor, yes.
The heating shall be turned on, when the temperature falls below a fixed threshold. But not when the door is opened, as this will trigger also. If the door is opened, a time of 15 minutes shall stop the trigger.

It would likely be easier to help if you exported your flow and pasted it in so we could import and poke around. If you’re not sure how to do that, here’s instructions from nodered’s user guide.

You’ve said you have an aqara door sensor. But aqara door sensors create a binary_sensor which either has state on or off depending on whether the door is open or closed. That doesn’t match up with what you’re showing in the screenshot:
Screen Shot 2021-03-03 at 11.40.31 AM

The poll state node shows the last state in the status below the node and its showing 20.1 which obviously isn’t a boolean. So did you mean the aqara door sensor or do you also have a Temp/Humidity sensor?

I’m going to assume sensor.flur is actually a temperature sensor because then the whole thing makes sense. Basically you have this:

  1. A poll state node which polls a temperature sensor and fires every x minutes if the temperature has fallen below a fixed threshold. This starts your flow
  2. A current state node which only lets those messages through if the door is closed
  3. A time node that only lets those messages through if the current time is from 06:00 to (whenver you stop the schedule in the evening)
  4. If the message has made it to this point then it turns on the heating and notifies you

If I am correct, your setup seems fine. You’re right that Events: State would have an issue because if the temperature dropped below your threshold during the night it wouldn’t fire in the morning. The alternative I could think of would be this:

  1. Replace the Poll: State with an Events: State node that has no condition (it fires anytime the temperature changes)
  2. Add an Inject node which fires at 6AM
  3. Connect both of those nodes to a Current State node which only allows messages to pass if the temperature is below your threshold
  4. Connect that node to the rest of your flow

This would work but I’m not sure its better or less confusing. Up to you. Another perhaps easier alternative would be to add a template sensor to HA which says this:

heater_on:
   unique_id: sensor_template_heater_on_86717a5c681d4a719ab74fd0c5eaf9a4
   value_template: "{{ now().hour >= 6 and now.hour <= schedule_end_hour and states('sensor.flux') | float < temp_threshold }}"

Then you can use that sensor in an Events: State node since it will only become on when the temperature is below a threshold and its in the right time range, thus it will kick on first thing in the morning.

The other thing to think about is what exactly does your Current State node do with the door sensor? If all that does is check whether the door is open or not that’s not actually meeting your original use case right? You said it should not turn on the heater until 15 minutes after the door is closed. Does that node have a JSONata expression in determining that or is that still a functional gap right now?

This is my flow:


[{"id":"dd16f012.7bced8","type":"tab","label":"Flur Heizung an","disabled":false,"info":""},{"id":"161e55e6.cd879a","type":"api-call-service","z":"dd16f012.7bced8","name":"","server":"c1af9201.0bc7e","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.heizung_flur","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":510,"y":460,"wires":[["ec77d123.20f258"]]},{"id":"fcd4d9ae.3b69f8","type":"time-range-switch","z":"dd16f012.7bced8","name":"Tag","lat":"","lon":"","startTime":"06:00","endTime":"20:00","startOffset":0,"endOffset":0,"x":450,"y":320,"wires":[["161e55e6.cd879a"],[]]},{"id":"ec77d123.20f258","type":"api-call-service","z":"dd16f012.7bced8","name":"","server":"c1af9201.0bc7e","version":1,"debugenabled":false,"service_domain":"notify","service":"pushnotify","entityId":"","data":"{\"message\":\"node-red: Heizung Flur eingeschaltet\",\"data\":{\"priority\":-1}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":520,"y":560,"wires":[[]]},{"id":"4952c3d0.1d9bcc","type":"poll-state","z":"dd16f012.7bced8","name":"","server":"9816e521.d65e58","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"300","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"sensor.flur","state_type":"num","halt_if":"19.5","halt_if_type":"num","halt_if_compare":"lte","outputs":2,"x":130,"y":80,"wires":[["368b237d.6a8294"],[]]},{"id":"368b237d.6a8294","type":"api-current-state","z":"dd16f012.7bced8","name":"","server":"9816e521.d65e58","version":1,"outputs":2,"halt_if":"false","halt_if_type":"bool","halt_if_compare":"is","override_topic":false,"entity_id":"switch.heizung_flur","state_type":"habool","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":300,"y":180,"wires":[["fcd4d9ae.3b69f8"],[]]},{"id":"c1af9201.0bc7e","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"9816e521.d65e58","type":"server","name":"Home Assistant","addon":true}]

in the screen shot you can see the temperature sensor. I want to add an additional binary_sensor for my door, this is not yet part of the flow. I can add a node for this, but I don’t know how to bring them together to add the 15 minutes wait period, it the door is opened.

The current state node is checking, if the switch is already turned on. I don’t want to fire the rest of the low, if the heating is already on, as I don’t want to receive multiple notifications.

Gotcha, I misunderstood. So if you want to insert a node in the flow which checks to ensure the door has been closed for at least 15 minutes before turning on the heater you could do it like this:

I just made up a name for your door sensor, put in whatever you actually use in entity ID. The JSONata expression in the box is this:

$entity().state = 'off' and $toMillis($entity().last_changed) < $millis() - 900000

For the record I am also assuming your aqara door sensor works like mine and the state of the binary sensor is off when the door is closed. If that’s incorrect then invert that first clause in the expression.

Regardless what this does is check to ensure two things are true:

  1. The door is closed
  2. The last time the state of the door changed was at least 15 minutes ago (or 900000ms ago)

The last_changed field is set to the last time the state of the entity changed, it is not updated if the only thing that changed was an attribute. Therefore basically the only time that timestamp will change is when the door opens or closes. Although of note it will also change when HA restarts since the entity is recreated which could create confusion occasionally but hopefully that will be a rare edge case.

Thanks, I will check this on the weekend.