hi all,
im using this python script since many time, but i don’t know from how many time i have this errror:
2020-05-07 15:42:52 INFO (MainThread) [homeassistant.components.automation] Executing [SYS] DEMUX RF Sensor
2020-05-07 15:42:52 INFO (MainThread) [homeassistant.components.automation] [SYS] DEMUX RF Sensor: Running script
2020-05-07 15:42:52 INFO (MainThread) [homeassistant.components.automation] [SYS] DEMUX RF Sensor: Executing step call service
2020-05-07 15:42:52 ERROR (MainThread) [homeassistant.components.automation] [SYS] DEMUX RF Sensor: Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'RfReceived'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 222, in async_render
return compiled.render(kwargs).strip()
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.7/site-packages/jinja2/sandbox.py", line 407, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'RfReceived'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 132, in async_prepare_call_from_config
template.render_complex(config[CONF_SERVICE_DATA_TEMPLATE], variables)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 71, in render_complex
return {key: render_complex(item, variables) for key, item in value.items()}
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 71, in <dictcomp>
return {key: render_complex(item, variables) for key, item in value.items()}
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 73, in render_complex
return value.async_render(variables)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 224, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'dict object' has no attribute 'RfReceived'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 153, in _async_step
self, f"_async_{cv.determine_script_action(self._action)}_step"
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 623, in _async_call_service_step
*self._prep_call_service_step(), blocking=True, context=self._context
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 252, in _prep_call_service_step
return async_prepare_call_from_config(self._hass, self._action, self._variables)
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 135, in async_prepare_call_from_config
raise HomeAssistantError(f"Error rendering data template: {ex}") from ex
homeassistant.exceptions.HomeAssistantError: Error rendering data template: UndefinedError: 'dict object' has no attribute 'RfReceived'
2020-05-07 15:42:52 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'dict object' has no attribute 'RfReceived'
2020-05-07 15:42:52 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'dict object' has no attribute 'RfReceived'
2020-05-07 15:42:52 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'dict object' has no attribute 'RfReceived'
2020-05-07 15:42:52 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'dict object' has no attribute 'RfReceived'
2020-05-07 15:53:23 INFO (MainThread) [homeassistant.components.automation] Executing [SYS] DEMUX RF Sensor
2020-05-07 15:53:23 INFO (MainThread) [homeassistant.components.automation] [SYS] DEMUX RF Sensor: Running script
2020-05-07 15:53:23 INFO (MainThread) [homeassistant.components.automation] [SYS] DEMUX RF Sensor: Executing step call service
2020-05-07 15:53:23 INFO (SyncWorker_17) [homeassistant.components.python_script] Executing rfbridge_demux.py: {'payload': '0x14000C'}
this is my Automation:
- alias: '[SYS] DEMUX RF Sensor'
trigger:
- platform: mqtt
topic: tele/temp/RESULT
action:
- service: python_script.rfbridge_demux
data_template:
payload: '{{trigger.payload_json.RfReceived.Data}}'
this is my script:
d = {
# Codici RF per Tasmota e per OMG
# Codici sensori magnetici per Tasmota
'0x4AD50A':['portone','ON','true'],
'0x4AD50E':['portone','OFF','true'],
'0x4AD506':['portone_bat','ON','false'],
#
'0x4A820A':['fin_sala','ON','true'],
'0x4A820E':['fin_sala','OFF','true'],
'0x4A8206':['fin_sala_bat','ON','false'],
#
'0xD9140A':['fin_bagnop','ON','true'],
'0xD9140E':['fin_bagnop','OFF','true'],
'0xD91406':['fin_bagnop_bat','ON','false'],
#
'0x5C5A0A':['fin_bagnog','ON','true'],
'0x5C5A0E':['fin_bagnog','OFF','true'],
'0x5C5A06':['fin_bagnog_bat','ON','false'],
#
'0x44350A':['fin_camera_vale','ON','true'],
'0x44350E':['fin_camera_vale','OFF','true'],
'0x443506':['fin_camera_vale_bat','ON','false'],
#
'0xD8040A':['fin_camera_cri','ON','true'],
'0xD8040E':['fin_camera_cri','OFF','true'],
'0xD80406':['fin_camera_cri_bat','ON','false'],
#
'0x3F7D0A':['fin_cucinap','ON','true'],
'0x3F7D0E':['fin_cucinap','OFF','true'],
'0x3F7D06':['fin_cucinap_bat','ON','false'],
#
'0xD85C0A':['fin_cucinag','ON','true'],
'0xD85C0E':['fin_cucinag','OFF','true'],
'0xD85C06':['fin_cucinag_bat','ON','false'],
#
'0x4AAE0A':['fin_camera_letto','ON','true'],
'0x4AAE0E':['fin_camera_letto','OFF','true'],
'0x4AAE06':['fin_camera_letto_bat','ON','false']
}
p = data.get('payload')
if p is not None:
if p in d.keys():
service_data = {'topic':'home/RF433/{}'.format(d[p][0]), 'payload':'{}'.format(d[p][1]), 'qos':0, 'retain':'{}'.format(d[p][2])}
else:
service_data = {'topic':'home/unknown', 'payload':'{}'.format(p), 'qos':0, 'retain':'false'}
logger.warning('<rfbridge_demux> Received unknown RF command: {}'.format(p))
hass.services.call('mqtt', 'publish', service_data, False)
the script resend the MQTT message too and all works fine, but i wont to remove this error.
some one have this error too?