Template Number Configuration Format

I have an mqtt sensor that holds a numeric value that is a percentage of progress.

mqtt:
  sensor:
    - name: "Elegoo N4plus Print Progress"
      unique_id: "sensor.elegoo_n4plus_print_progress"
      unit_of_measurement: '%'
      icon: mdi:printer-3d-nozzle
      state_topic: "neptune4p/printprogress"
      qos: 0

As an example the state of the above entity is currently set to 65

I wanted to use this sensor value in a mushroom number card to show progress of a 3d print, but the mushroom card expects only a number or input_number.

I’m trying to use a template to populate a number with the value from the sensor; but I can’t seem to get the syntax right. Anyone have an example of something similar or see where I might be off-track?

template:
  - number:
    - name: 3d_print_progress
      unique_id: 3d_print_progress
      state: "{{ states('sensor.elegoo_n4plus_print_progress') }}"
      step: "1"
      set_value: 
        action: number.set_value
        target: number.3d_print_progress
        data: "{{ value }}"

I’ve also tried (without success)

data: "{{ states('sensor.elegoo_n4plus_print_progress') }}"

I’m seeing this in the logs after I re-load the template entities using developer tools

Invalid config for 'template' at configuration.yaml, line 1223: expected dictionary 'number->0->set_value->0', got 'n'
Invalid config for 'template' at configuration.yaml, line 1219: invalid template (TemplateSyntaxError: Encountered unknown tag 'states'.) for dictionary value 'number->0->state', got '{% states(sensor.sensor.elegoo_n4plus_print_progress) %}' Invalid config for 'template' at configuration.yaml, line 1223: expected dictionary 'number->0->set_value->0', got 'n'
Invalid config for 'template' at configuration.yaml, line 1219: expected dictionary 'number->0->set_value->0', got '{'
Invalid config for 'template' at configuration.yaml, line 1220: expected dictionary 'number->0->set_value->0', got '{'
Invalid config for 'template' at configuration.yaml, line 1221: expected a dictionary for dictionary value 'number->0->set_value->0->target', got None

Thanks!
Joe

My guess would be that set_value should contain a list, so try adding a dash before action.

Don’t think that will fix your template entity though, as you sort of end up with an infinite recursion where the set_value action will repeatedly execute itself.

Seems more logical to just leave it blank (as in null), or set to an empty list [].

Thanks! Your list comment solved it for me! :slight_smile: I was also wondering about some kind of loop. I ended up resolving this by just using delay: 1 as the set_value action; it would not let me leave it empty

  - number:
    - name: 3d_print_progress
      unique_id: 3d_print_progress
      state: "{{ states('sensor.elegoo_n4plus_print_progress') }}"
      step: "1"
      set_value: 
        - delay: 1

target needs entity_id, area_id, or device_id:

...
      set_value: 
        action: number.set_value
        target: 
          entity_id: number.3d_print_progress
        data: "{{ value }}"