Timer entity name in automation

Hi guys all I need to complete my heating boost automations is the name of the timer that has just finished. So 2 questions if I may.

  1. how do I get the name of it (automation to follow)
  2. are the properties of these objects documented anywhere so I dont have to keep asking?

the string I am trying to create is input_boolean.boost_[room name]_heating and the room name will come from the time just finished.

Thanks loads

- id: 'Heating: Turn Off When Boost Timer is Finished'
  alias: 'Heating: Turn Off When Boost Timer is Finished'
  description: ''
  trigger:
  - event_data:
      entity_id: timer.vestibule_boost_timer
    event_type: timer.finished
    platform: event
  - event_data:
      entity_id: timer.livingroom_boost_timer
    event_type: timer.finished
    platform: event
  - event_data:
      entity_id: timer.office_boost_timer
    event_type: timer.finished
    platform: event
  - event_data:
      entity_id: timer.kitchen_boost_timer
    event_type: timer.finished
    platform: event
  - event_data:
      entity_id: timer.bathroom_boost_timer
    event_type: timer.finished
    platform: event
  - event_data:
      entity_id: timer.katrin_boost_timer
    event_type: timer.finished
    platform: event
  - event_data:
      entity_id: timer.bedroom_boost_timer
    event_type: timer.finished
    platform: event
  condition: []
  action:
  - data_template:
      entity_id: input_boolean.boost_{{trigger.name.split('_')[0].split('.')[1]}}_heating
    service: input_boolean.turn_off

A state_changed event will have these values in trigger.event.data:

EVENT STATE_CHANGED

So you can get the string you want with this:

      entity_id: input_boolean.boost_{{ trigger.event.data.new_state.object_id.split('_')[0] }}_heating

Thanks for the response unfortunately I get

2020-01-21 05:50:41 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: 'dict object' has no attribute 'new_state'

and when I set homeassistant.core to debug logging I get this

2020-01-21 06:29:22 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.heating_turn_off_when_boost_timer_is_finished, old_state=<state automation.heating_turn_off_when_boost_timer_is_finished=on; last_triggered=2020-01-21T06:20:54.025816+00:00, id=Heating: Turn Off When Boost Timer is Finished, friendly_name=Heating: Turn Off When Boost Timer is Finished @ 2020-01-21T06:23:28.240251+00:00>, new_state=<state automation.heating_turn_off_when_boost_timer_is_finished=on; last_triggered=2020-01-21T06:29:22.023017+00:00, id=Heating: Turn Off When Boost Timer is Finished, friendly_name=Heating: Turn Off When Boost Timer is Finished @ 2020-01-21T06:23:28.240251+00:00>>

is there any way I can log out the variables and properties?

Oops, sorry, my bad! I had the state_changed event on the brain since I had been helping someone else with that earlier.

You can see all the data the event contains by using the EVENTS tab of the Developer Tools page. Enter timer.finished where it says “Event to subscribe to”, then click START LISTENING. When the event fires it will list it out with all its data. Here is an example from my system:

Event 0 fired 8:35 AM:
{
    "event_type": "timer.finished",
    "data": {
        "entity_id": "timer.nest_thm_wait"
    },
    "origin": "LOCAL",
    "time_fired": "2020-01-21T14:35:43.003542+00:00",
    "context": {
        "id": "6d95d209b427418e9b07d923fc378d7e",
        "parent_id": null,
        "user_id": null
    }
}

So try this instead:

      entity_id: input_boolean.boost_{{ trigger.event.data.entity_id.split('.',1)[1].split('_')[0] }}_heating

Amazing!!! worked perfectly thanks soooooo much for your help! And for the info about the events tab, never used it but I shall from now on.

1 Like