Numberbox: Where to add mqtt.publish service

Newbie, can’t get my head around this.

I am using this numberbox card from htmltiger.

type: custom:numberbox-card
border: true
entity: input_number.box1
name: PWM

And I have defined input number for it.

name: “Numeric Input Box”
initial: 30
min: 0
max: 100
step: 1
mode: box

My issue is now that I want to send / publish the box1 value each time it is changed.
I have not been able to figure out where / how to add the call for the mqtt.publish service.
And how do I send it in json format

service: mqtt.publish
  topic: /skorsten_vent/commands
  payload: xxx

Use an automation.

  - platform: state
    entity_id: input_number.box1
  - service: mqtt.publish
      topic: /skorsten_vent/commands
      payload_template: "{{ trigger.to_state.state }}"

The null to: triggers on all state changes, but not attribute changes of the entity. Leaving it out altogether triggers on attribute changes as well. Not needed or wanted in your use case.

Note that because you have defined an initial value for the input_number, this automation will publish 30 every time home assistant is restarted or input_numbers are reloaded. You may want to re-think having that option.

Thanks for pointing me in the right direction.
It never crossed my mind that I needed an automation to connect to the input number.

Still new to this and are doing it by try and error.
Do you have any place you can recommend to get an overview over how HA interact.
I am an okay programmer in more languages and specially Python but I think that it is a bit hard to getting started with HA.
Newbie starting with a DIY mqtt project may not be the easy way to get familiar with HA

And the initial value was just to getting started. I will read back the value from my arduino project on startup / connection and set that value in the input number box so they as synchronized.