Can you define helpers inside a package?

I just started learning about packages. I want to define helpers (including timers), templates and automations.

Sadly the Packages documentation lacks a list of exactly what you can include and examples of how to do it. The implication is that you can define anything that you could define under the homeassistant: key in configuration.yaml and input_boolean is mentioned in passing – I assumed that if you can define them, you can also define input_number, input_text, and timer.

However, when I tried it with some test code, I got configuration warnings (that look rather like errors)

Configuration warnings

Setup of package ‘heating_x2_definitions’ failed: integration ‘input_number’ cannot be merged, expected a dict
Setup of package ‘heating_x2_definitions’ failed: integration ‘input_text’ cannot be merged, expected a dict
Setup of package ‘heating_x2_definitions’ failed: integration ‘timer’ cannot be merged, expected a dict

Is that because they are not supported, or did I just get the syntax wrong?

###
### ZZZ Test room heating control 	
###

input_number:
  - zzz_test_room_heating_manual_temperature:
      name: ZZZ Test room heating manual temperature
      min: 0
      max: 100
      step: 0.5
      mode: box
      icon: mdi:temperature-celsius

  - zzz_test_room_heating_required_temperature:
      name: ZZZ Test room heating required temperature
      min: 0
      max: 100
      step: 0.5
      mode: box
      icon: mdi:temperature-celsius

input_text:
  - zzz_test_room_heating_setting_reason:
      name: ZZZ Test room heating setting reason
      initial: “”
      icon: mdi:card-text-outline

timer:
  - zzz_test_room_heating_manual_override_timer:
      name: ZZZ Test room heating manual override timer
      duration: "00:00:00"
      restore: true
      icon: mdi:av-timer

  - zzz_test_room_heating_warmup_timer:
      name: ZZZ Test room heating warmup timer
      duration: "00:00:00"
      restore: true
      icon: mdi:av-timer

  - zzz_test_room_heating_door_or_window_open_timer:
      name: ZZZ Test room heating door or window open timer
      duration: "00:00:00"
      restore: true
      icon: mdi:av-timer

  - zzz_test_room_heating_room_unoccupancy_timer:
      name: ZZZ Test room heating room unoccupancy timer
      duration: "00:00:00"
      restore: true
      icon: mdi:av-timer

  - zzz_test_room_heating_echoblock_timer:
      name: ZZZ Test room heating echoblock timer
      duration: "00:00:00"
      restore: true
      icon: mdi:av-timer

template:
  - sensor: 
    - name: ZZZ Test room west TRV set temperature
      unique_id: zzz_test_room_west_trv_set_temperature
      unit_of_measurement: 'C'
      icon: mdi:thermometer
      state: "{{ state_attr('climate.zzz_test_room_west_trv', 'temperature') }}"
  - sensor:
    - name: ZZZ Test room west TRV measured temperature 
      unique_id: zzz_test_room_west_trv_measured_temperature
      unit_of_measurement: 'C'
      icon: mdi:thermometer
      state: "{{ state_attr('climate.zzz_test_room_west_trv', 'current_temperature') }}"
  - binary_sensor:
    - name: ZZZ Test room west TRV heat demand
      unique_id: zzz_test_room_west_trv_heat_demand
      icon: mdi:heat-wave
      state: "{{ float(state_attr('climate.zzz_test_room_west_trv, 'temperature'),0) > float(state_attr('climate.zzz_test_room_west_trv, 'current_temperature'),99) }}" 

automation:
  - id: zzz_test_room_heating_control
    alias: ZZZ Test room heating control
    description: Controls the heating for the ZZZ Test room using the ZZZ Test room heating schedule calendar
    use_blueprint:
      path: AndySymons/heating_x2.yaml
      input:
        thermostat_controls:
        - zzz_test_room_west_trv
        - zzz_test_room_east_trv
        away_switch: input_boolean.away
        door_or_window_open_sensors: []
        room_occupancy_sensors: []
        room_calendar: calendar.zzz_test_room_heating_schedule
        manual_temperature: input_number.zzz_test_room_heating_manual_temperature
        required_temperature: input_number.zzz_test_room_heating_required_temperature
        setting_reason: input_text.zzz_test_room_heating_setting_reason
        door_or_window_open_timer: timer.zzz_test_room_heating_door_or_window_open_timer
        unoccupancy_timer: timer.zzz_test_room_heating_room_unoccupancy_timer
        warmup_timer: timer.zzz_test_room_heating_warmup_timer
        manual_override_timer: timer.zzz_test_room_heating_manual_override_timer
        echoblock_timer: timer.zzz_test_room_heating_echoblock_timer
        minimum_thermostat_temperature: 5
        maximum_thermostat_temperature: 30
        away_temperature: 5
        background_temperature: 5
        door_or_window_open_period: 00:02:00
        unoccupancy_period: 00:30:00
        warmup_period: 02:00:00
        manual_override_period: 02:00:00

After reloading the configuration anyway, there were (predictably) no helpers, the template sensors look OK and the automation is generated but ‘unavailable’ and cannot be edited from the UI.

You can do it.

Can you share your package yaml that didn’t work?

It is there in the posting above (it took me a couple of minutes).
What you see is the content of /config/packages/heating_x2_definitions.yaml.
There is another package in the same directory that is working, so I seem to have set up packages OK.

sorry - was on my phone and didn’t scroll up!

OK, you just got the formatting a little wrong. I’ve modified them for you (I have never used an input_text so not sure about that one but guessing it is the same):

input_number:
  zzz_test_room_heating_manual_temperature: # note no preceding dash
    name: ZZZ Test room heating manual temperature
    min: 0
    max: 100
    step: 0.5
    mode: box
    icon: mdi:temperature-celsius

  zzz_test_room_heating_required_temperature:
    name: ZZZ Test room heating required temperature
    min: 0
    max: 100
    step: 0.5
    mode: box
    icon: mdi:temperature-celsius

input_text:
  zzz_test_room_heating_setting_reason:
    name: ZZZ Test room heating setting reason
    initial: “”
    icon: mdi:card-text-outline

timer:
  zzz_test_room_heating_manual_override_timer:
    name: ZZZ Test room heating manual override timer
    duration: "00:00:00"
    restore: true
    icon: mdi:av-timer

  zzz_test_room_heating_warmup_timer:
    name: ZZZ Test room heating warmup timer
    duration: "00:00:00"
    restore: true
    icon: mdi:av-timer

  zzz_test_room_heating_door_or_window_open_timer:
    name: ZZZ Test room heating door or window open timer
    duration: "00:00:00"
    restore: true
    icon: mdi:av-timer

  zzz_test_room_heating_room_unoccupancy_timer:
    name: ZZZ Test room heating room unoccupancy timer
    duration: "00:00:00"
    restore: true
    icon: mdi:av-timer

  zzz_test_room_heating_echoblock_timer:
    name: ZZZ Test room heating echoblock timer
    duration: "00:00:00"
    restore: true
    icon: mdi:av-timer

edited for typos

zzz_test_room_heating_package
Yep! Many thanks. :pray: So an elementary YAML error. I always get confused about when the dashes are needed :confounded:

This code now creates the helpers and template sensors correctly. The automation is incorrect – can you spot an obvious reason why?

Always look at the examples in the documentation. e.g.

https://www.home-assistant.io/integrations/input_number/

2 Likes

YAML primers say use a dash for items in a list. You are right about the documentation of course – so I suppose the items under input_number are somehow not a list?

Correct, they are a dictionary. Other things that use dictionaries instead of lists:

script, all the other input_* helpers, themes, customize, utility_meters, and more.

1 Like

What is the error now (should be different now the helpers are working)?

It is unchanged – the automation appears as ‘unavailable’ in the UI and cannot be edited.

I have now started a new topic for this question: Automation created by package unavailable