Use object_id for different domain

I know I’m over simplifying how I’m writing this and so I’m hoping I can get some help. I want to use the object_id of a input_number to select the associated climate entity (they both have the same object_id) and then set the temperature to the input_number that triggered the automation. I think it should be something along the lines of: -

  action:
  - service: climate.set_temperature
    data:
      entity_id: climate.{{trigger.to_state.object_id}}
      temperature: '{{ (states.trigger.entity_id.state|float) }}'

I can’t find a suitable example in the docs. Can someone point me in the right direction please?

Not an example but there’s this: https://www.home-assistant.io/docs/automation/templating/#trigger-state-object

What you have should work, assuming you are on the current version. If below 0.115 though it should be data_template.

Thanks tom_l,
It’s good to know I’m on the right track. I took information from your suggestion and here https://www.home-assistant.io/docs/automation/templating/
I’m on 0.115.2, need to improve my detective skills now!

Is it working or are you getting an error?

I didn’t see the target temperature change for the climate, so I thought I had it completely wrong, so I didn’t think to check the logs. Now I look there’s this in the log

Logger: homeassistant.components.automation.input_number_change_temp
Source: helpers/service.py:140
Integration: Automation (documentation, issues)
First occurred: 16:18:40 (10 occurrences)
Last logged: 16:27:33

  • Input_Number Change Temp: Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: ‘None’ has no attribute ‘state’
  • While executing automation automation.input_number_change_temp

Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 285, in async_render return compiled.render(kwargs).strip() File “/usr/local/lib/python3.8/site-packages/jinja2/environment.py”, line 1090, in render self.environment.handle_exception() File “/usr/local/lib/python3.8/site-packages/jinja2/environment.py”, line 832, in handle_exception reraise(*rewrite_traceback_stack(source=source)) File “/usr/local/lib/python3.8/site-packages/jinja2/_compat.py”, line 28, in reraise raise value.with_traceback(tb) File “”, line 1, in top-level template code File “/usr/local/lib/python3.8/site-packages/jinja2/filters.py”, line 794, in do_float return float(value)

How are you test triggering the automation?

Read the blue note here: https://www.home-assistant.io/docs/automation/templating/#trigger-state-object

I’m changing the input_number value using a slider I have set up.

Here’s the full automation: -

- id: input_number_change_temp
  alias: Input_Number Change Temp
  trigger:
  - platform: state
    entity_id: input_number.l_temp, input_number.b_temp, input_number.i_temp, input_number.r_temp
  action:
  - service: climate.set_temperature
    data:
      entity_id: climate.{{trigger.to_state.object_id}}
      temperature: '{{ (states.trigger.entity_id.state|float) }}'
  initial_state: 'true'
  mode: single

It was the temperature part of the service data that was causing me the problem. Instead of calling states.trigger.entity_id.state I needed trigger.to_state.state

All working now :+1:

1 Like