API error, turning scene on...but only sometimes 🤔

Hi all,
This is driving me insane and I’ve finally admitted defeat.

I have this (messy) flow, which turns off two local radiators when the rear door is open for more than 15 seconds and if it is open for more than 5 minutes it turns off all of the heating downstairs:

It works, the scenes are created automatically and the radiators/'stat are turned on or off, irrespective of whether the API error is showing for the first scene (the local rads) or not. :face_with_raised_eyebrow: If the door is open >15s but <5m the first scene call service node will show that it has been successfully called, as it should, >5m and it shows that an API error has occurred. Debug shows:

21/04/2021, 07:00:43 node: Turn on scene
msg : string[103]
Call-service API error.  Error Message: string value is None for dictionary value @ data['preset_mode']

I also end up with the following in my HA log:

Logger: homeassistant.core
Source: core.py:1434
First occurred: 7:01:01 (1 occurrences)
Last logged: 7:01:01

Error executing service: <ServiceCall scene.turn_on (c:282a072f532dd91fd1d44609b4a4f789): entity_id=['scene.rear_door_extended_snapshot']>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1496, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 206, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 649, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 692, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/homeassistant/scene.py", line 313, in async_activate
    await async_reproduce_state(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 115, in async_reproduce_state
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 109, in worker
    await platform.async_reproduce_states(  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/climate/reproduce_state.py", line 84, in async_reproduce_states
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/components/climate/reproduce_state.py", line 67, in _async_reproduce_states
    await call_service(SERVICE_SET_PRESET_MODE, [ATTR_PRESET_MODE])
  File "/usr/src/homeassistant/homeassistant/components/climate/reproduce_state.py", line 46, in call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1434, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 218, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 341, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 337, in _exec
    v = func(v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: string value is None for dictionary value @ data['preset_mode']

Can anyone tell me what is causing this and how I can fix whatever I’ve done wrong please?

Exported flow:

[{"id":"b0242f35.84c88","type":"tab","label":"Heating","disabled":false,"info":""},{"id":"7476ca0e.ae2a34","type":"comment","z":"b0242f35.84c88","name":"Rear door opened, wait 15 seconds; turn rear door/washroom radiators off. If door is still open after 5 minutes, turn off heating downstairs. Reset to previous states when door closed","info":"","x":610,"y":40,"wires":[]},{"id":"b123daa6.9b8338","type":"server-state-changed","z":"b0242f35.84c88","name":"Rear door open?","server":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.rear_door_contact_sensor_contact","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":100,"y":200,"wires":[["1b9f54ed.73425b","216e0f53.33a7e"],["712fa4df.1bfa8c","a879d3aa.73f91","b8f58910.0a6998","3845932f.8d754c"]]},{"id":"1b9f54ed.73425b","type":"api-call-service","z":"b0242f35.84c88","name":"Create scene","server":"","version":1,"debugenabled":false,"service_domain":"scene","service":"create","entityId":"","data":"{\"scene_id\":\"rear_door_snapshot\",\"snapshot_entities\":[\"climate.washroom_radiator\",\"climate.rear_door_radiator\"]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":270,"y":100,"wires":[["712fa4df.1bfa8c"]]},{"id":"229ed6f5.58eeda","type":"api-call-service","z":"b0242f35.84c88","name":"Turn radiators off","server":"","version":1,"debugenabled":false,"service_domain":"climate","service":"turn_off","entityId":"{{payload.entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":890,"y":100,"wires":[[]]},{"id":"712fa4df.1bfa8c","type":"trigger","z":"b0242f35.84c88","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"15","extend":false,"overrideDelay":false,"units":"s","reset":"off","bytopic":"all","topic":"topic","outputs":1,"x":490,"y":100,"wires":[["9a0e6939.a17568"]]},{"id":"9a0e6939.a17568","type":"ha-get-entities","z":"b0242f35.84c88","server":"","name":"Find rads that aren't off","rules":[{"property":"entity_id","logic":"includes","value":"climate.washroom_radiator, climate.rear_door_radiator","valueType":"str"},{"property":"state","logic":"is_not","value":"off","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":680,"y":100,"wires":[["229ed6f5.58eeda"]]},{"id":"216e0f53.33a7e","type":"api-call-service","z":"b0242f35.84c88","name":"Create scene","server":"","version":1,"debugenabled":false,"service_domain":"scene","service":"create","entityId":"","data":"{\"scene_id\":\"rear_door_extended_snapshot\",\"snapshot_entities\":[\"climate.downstairs\"]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":270,"y":160,"wires":[["b8f58910.0a6998"]]},{"id":"b8f58910.0a6998","type":"trigger","z":"b0242f35.84c88","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"min","reset":"off","bytopic":"all","topic":"topic","outputs":1,"x":490,"y":160,"wires":[["82f15b5d.43cab8"]]},{"id":"929b9999.c0a458","type":"api-call-service","z":"b0242f35.84c88","name":"Turn radiators off","server":"","version":1,"debugenabled":false,"service_domain":"climate","service":"turn_off","entityId":"{{payload.entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":890,"y":160,"wires":[[]]},{"id":"82f15b5d.43cab8","type":"ha-get-entities","z":"b0242f35.84c88","server":"","name":"Find rads that aren't off","rules":[{"property":"entity_id","logic":"includes","value":"climate.downstairs","valueType":"str"},{"property":"state","logic":"is_not","value":"off","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":680,"y":160,"wires":[["929b9999.c0a458"]]},{"id":"ae4cfe5e.775ca","type":"api-call-service","z":"b0242f35.84c88","name":"Turn on scene","server":"","version":1,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"scene.rear_door_extended_snapshot","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":480,"y":280,"wires":[[]]},{"id":"a879d3aa.73f91","type":"api-current-state","z":"b0242f35.84c88","name":"Is downstairs off?","server":"","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"climate.downstairs","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":290,"y":280,"wires":[["ae4cfe5e.775ca"],[]]},{"id":"3845932f.8d754c","type":"api-call-service","z":"b0242f35.84c88","name":"Turn on scene","server":"","version":1,"debugenabled":false,"service_domain":"scene","service":"turn_on","entityId":"scene.rear_door_snapshot","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":280,"y":220,"wires":[["573e68ba.510ea8"]]},{"id":"573e68ba.510ea8","type":"debug","z":"b0242f35.84c88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":430,"y":220,"wires":[]}]

Also, if anyone has any suggestions on how to improve or clean up this mess please go ahead!

Thanks.

If I understand you correctly, the call service node that turns on the scene when the door is closed is the only node that gives you errors. Maybe there is some message being sent that interferes with the node working correctly. In this case, try to simply just remove all the messages and put something simple. Like Payload = ON. You could try to do that with a change node.

1 Like

I’ve never worked with scenes, so I can’t help troubleshoot this. But, since you only have two heaters, then why bother with scenes at all?

I’m using scenes so that I can capture the setting of the TRVs on the two rads and, separately, the main thermostat at the time that the door is opened. So then, once its closed it goes back to the same setting as before.

Over complicated, possibly… :joy:

Ya’ think?

You could use global.set in a function node to save the settings in Node Red.