Need help changing input_number values from Telegram

I succesfully managed to setup automations to turn my heatpump/AC on/off, and choosing the operation mode from Telegram.
All I need to add now is the possibility to adjust the temperature setpoint (the predefined sane default might not suit my wishes…). Same would in theory apply for the fan direction and speed values - but I hardly ever change those from auto, so not a real issue there :wink:
The value is defined by an input_number like this:

    input_number:
      actemp:
        name: Temperatur
        initial: 20
        min: 16
        max: 30
        step: 1
        icon: mdi:thermometer

Can anyone direct me how to create the needed automation for adjusting the setpoint?
I really don’t want to create individual configurations for all thinkable temperatures, but would like to be able to enter it directly from Telegram.

My automations.yaml look like this at the moment:

- id: actelegram
  alias: Telegram - Control AC
  hide_entity: true
  trigger:
  - event_data:
      data: /ac
    event_type: telegram_callback
    platform: event
  action:
  - service: notify.telegram
    data:
      message: 'On / Off: {{ states.input_boolean.aconoff.state }}

        Funktion: {{ states.input_select.acmodus.state }}

        Temperatur: {{ states.input_number.actemp.state }}°C

        Blæser: {{ states.input_number.acfan.state }} - 0 = Auto

        V-retning: {{ states.input_number.acdirection.state }} - 0 = Auto

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/start
- id: aconoff
  alias: Telegram - AC On/Off
  hide_entity: true
  trigger:
  - event_data:
      data: /aconoff
    event_type: telegram_callback
    platform: event
  action:
  - service: homeassistant.toggle
    entity_id: input_boolean.aconoff
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'On / Off: {{ states.input_boolean.aconoff.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/start
- id: acfunction
  alias: Telegram - Control AC Function
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunction
    event_type: telegram_callback
    platform: event
  action:
  - service: notify.telegram
    data:
      message: 'Vælg funktion. Aktuel funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - Auto:/acfunctionauto, Køl:/acfunctioncool, Varme:/acfunctionheat, Affugtning:/acfunctiondry, Vifte:/acfuntionfan, Start:/start
- id: acfunctionauto
  alias: Telegram - Control AC Function Auto
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunctionauto
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Auto
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/start
- id: acfunctioncool
  alias: Telegram - Control AC Function Køl
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunctioncool
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Køling
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/start
- id: acfunctionheat
  alias: Telegram - Control AC Function Varme
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunctionheat
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Varme
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/start
- id: acfunctiondry
  alias: Telegram - Control AC Function Affugtning
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunctiondry
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Affugtning
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/start
- id: acfuntionfan
  alias: Telegram - Control AC Function Vifte
  hide_entity: true
  trigger:
  - event_data:
      data: /acfuntionfan
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Vifte
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/start
  trigger:
    platform: event
    event_type: telegram_command
    event_data:
      command: /set_temp
  action:
    service: input_number.set_value
    data_template:
      entity_id: input_number.actemp
      value: "{{ trigger.event.data.args[0] }}"

Send /set_temp 25 from telegram sets the input number to 25.

You could add a condition to ensure the additional data you send was a number between 16 and 30, and return an error if not, or add a further action that confirms the change.

2 Likes

This is great!
I didn’t know you could do this. Maybe I should have but I didn’t!
Thanks!

1 Like

Yeah, you can join the args together so it picks up everything after the keyword as a oner too. It’s pretty flexible.

Hmm… not working so far (changed a few values to make it more consistent (consistent in my logic that is :wink: )) … No errors in the log either :frowning:

- id: actemperature
  alias: Telegram - Control AC Temperature
  hide_entity: true
  trigger:
  - event_data:
      command: /setactemperature
    event_type: telegram_command
    platform: event
  action:
  - service: input_number.set_value
    data:
      entity_id: input_number.actemp
      value: '{{ trigger.event.data.args[0] }}'

Did I mess everything up?

Automation switched on? Showing as triggered in the logbook? :sunglasses:

Switched on, and trigger date updates as expected - but value stays the same.

And there’s no error??

Cannot resolve template or invalid value or something?

Oh, you have data not data_template in your action.

Yup… I did :slight_smile:
changing to data_template solved it :smiley:
Thanks a lot @anon43302295

1 Like

No worries :sunglasses:

Can you mark my first post as solved please, might help people in the future :+1:

Sure :slight_smile:
Should anyone care, my “final” automations.yaml look like this (things pertaining to Telegram/heatpump) including a Sensor “status” message - messages in Danish, but I think it should be possible to get the idea anyhow:

- id: acsend
  alias: Varmepumpe Send
  hide_entity: true
  trigger:
  - platform: state
    entity_id: input_select.acmodus
  - platform: state
    entity_id: input_number.actemp
  - platform: state
    entity_id: input_number.acfan
  - platform: state
    entity_id: input_number.acdirection
  - platform: state
    entity_id: input_boolean.aconoff
  action:
  - service: mqtt.publish
    data:
      topic: /homeassist/ac/cmd
      payload_template: heatpumpir,panasonic_lke,{% if states.input_boolean.aconoff.state
        == 'on' %}1{% elif states.input_boolean.aconoff.state == 'off' %}0{% endif
        %},{% if states.input_select.acmodus.state == 'Auto' %}1{% elif states.input_select.acmodus.state
        == 'Varme' %}2{% elif states.input_select.acmodus.state == 'Køling' %}3{%
        elif states.input_select.acmodus.state == 'Avfukting' %}4{% elif states.input_select.acmodus.state
        == 'Vifte' %}5{% endif %},{{states.input_number.acfan.state|int}},{{states.input_number.actemp.state|int}},{{states.input_number.acdirection.state|int}},0
  - service: homeassistant.turn_off
    entity_id: input_boolean.acsend
- id: starttelegram
  alias: Telegram - Start
  hide_entity: true
  trigger:
  - event_data:
      command: /start
    event_type: telegram_command
    platform: event
  action:
  - service: notify.telegram
    data:
      message: 'Velkommen til din assistent:'
      data:
        inline_keyboard:
        - Sensorer:/sensors, Varmepumpe:/ac
- id: returnstarttelegram
  alias: Telegram - re-Start
  hide_entity: true
  trigger:
  - event_data:
      data: /restart
    event_type: telegram_callback
    platform: event
  action:
  - service: notify.telegram
    data:
      message: 'Velkommen til din assistent:'
      data:
        inline_keyboard:
        - Sensorer:/sensors, Varmepumpe:/ac
- id: showsensors
  alias: Telegram - Show sensor values
  hide_entity: true
  trigger:
  - event_data:
      data: /sensors
    event_type: telegram_callback
    platform: event
  action:
  - service: notify.telegram
    data:
      message: 'AC - Temperatur: {{ states(''sensor.temperatureac'') }}°C

        Køleskab - Batteri: {{ states(''sensor.voltagefridge'') }}V

        Køleskab - Temperatur: {{ states(''sensor.temperaturefridge'') }}°C

        Kontor - Temperatur: {{ states(''sensor.temperaturekontor'') }}°C

        Kontor - Barometer: {{ states(''sensor.barometerkontor'') }} hPa

        Kontor - Luftfugtighed: {{ states(''sensor.luftfugtighedkontor'') }} % RF

        Kontor - Lysstyrke: {{ states(''sensor.luxkontor'') }} lx

        Netværk - IP: {{ states(''sensor.ip_info'') }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/restart
- id: actelegram
  alias: Telegram - Control AC
  hide_entity: true
  trigger:
  - event_data:
      data: /ac
    event_type: telegram_callback
    platform: event
  action:
  - service: notify.telegram
    data:
      message: 'On / Off: {{ states.input_boolean.aconoff.state }}

        Funktion: {{ states.input_select.acmodus.state }}

        Temperatur: {{ states.input_number.actemp.state }}°C

        Blæser: {{ states.input_number.acfan.state }} - 0 = Auto

        V-retning: {{ states.input_number.acdirection.state }} - 0 = Auto

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/restart
- id: aconoff
  alias: Telegram - AC On/Off
  hide_entity: true
  trigger:
  - event_data:
      data: /aconoff
    event_type: telegram_callback
    platform: event
  action:
  - service: homeassistant.toggle
    entity_id: input_boolean.aconoff
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'On / Off: {{ states.input_boolean.aconoff.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/restart
- id: acfunction
  alias: Telegram - Control AC Function
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunction
    event_type: telegram_callback
    platform: event
  action:
  - service: notify.telegram
    data:
      message: 'Vælg funktion. Aktuel funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - Auto:/acfunctionauto, Køl:/acfunctioncool, Varme:/acfunctionheat, Affugtning:/acfunctiondry, Vifte:/acfuntionfan, Start:/restart
- id: acfunctionauto
  alias: Telegram - Control AC Function Auto
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunctionauto
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Auto
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/restart
- id: acfunctioncool
  alias: Telegram - Control AC Function Køl
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunctioncool
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Køling
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/restart
- id: acfunctionheat
  alias: Telegram - Control AC Function Varme
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunctionheat
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Varme
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/restart
- id: acfunctiondry
  alias: Telegram - Control AC Function Affugtning
  hide_entity: true
  trigger:
  - event_data:
      data: /acfunctiondry
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Affugtning
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/restart
- id: acfuntionfan
  alias: Telegram - Control AC Function Vifte
  hide_entity: true
  trigger:
  - event_data:
      data: /acfuntionfan
    event_type: telegram_callback
    platform: event
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.acmodus
      option: Vifte
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Ny funktion: {{ states.input_select.acmodus.state }}

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/restart
- id: actemperature
  alias: Telegram - Control AC Temperature
  hide_entity: true
  trigger:
  - event_data:
      data: /actemperature
    event_type: telegram_callback
    platform: event
  action:
  - service: notify.telegram
    data:
      message: 'Brug /acsettemperature til at vælge temperatursetpunkt. Gyldige værdier er 16 - 30 °C

        '
- id: acsettemperature
  alias: Telegram - Set AC Temperature
  hide_entity: true
  trigger:
  - event_data:
      command: /acsettemperature
    event_type: telegram_command
    platform: event
  action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.actemp
      value: '{{ trigger.event.data.args[0] }}'
  - delay: 00:00:01
  - service: notify.telegram
    data:
      message: 'Nyt temperatursetpunkt: {{ states.input_number.actemp.state }}°C

        '
      data:
        inline_keyboard:
        - On/Off:/aconoff, Funktion:/acfunction, Temperatur:/actemperature, Start:/restart
2 Likes