Number variable in string - convert to string in action

Hi there,

I am currently trying to write a small script for HomeMatic on-for-timer. I know the service I found is working, as executing it manually works. But when I try to get it into a script it starts to fail.

To be exact: It also works in the script, as long as I don’t put the ON_TIME to a variable and hardcode the value. As soon as I set a template variable, it does not work any more.

When digging around in the script debugger, I found one notable difference:
When setting the variable manually, the script outputs ON_TIME as '10' (with quotes).
When I do the same with a variable, it leaves the quotes away.

Now question - how do I always get the quotes?

I already tried to make on_seconds a string - that also didn’t change anything. That’s probably a totally simple reason :frowning:

on_for_timer:
  alias: On for timer
  fields:
    entity_id:
      description: 'entity_id'
      example: 'switch.wz_fernseher'
      selector:
        entity:
    on_seconds:
      description: 'Seconds after which the device will be shut down again'
      selector:
        number:
          
  sequence:
    - service: homematic.put_paramset
      data:
        address: "{{ state_attr(entity_id, 'id') }}:1"
        interface: rf
        paramset:
          ON_TIME: "{{ on_seconds | string }}"
          STATE: true
        paramset_key: VALUES


Thanks for any help!
Matthias

1 Like

I’ve found a solution - a very hacky solution.

To force Home Assistant to make a string out of the result, I just prepended a 0. That way Home Assistant now evaluates ON_TIME to ON_TIME: '010' - which HomeMatic can parse. Nobody cares about octal values (which the 0 actually would trigger, so it seems to be fine).

However - is there a better solution? This currently very much looks like a bug to me …

Matthias

1 Like

Hi @klassm - Did you ever find a “real” solution? I am running into something very similar.

This hard coded example works:

roomba_clean:
  alias: Roomba - Clean
  mode: single
  sequence:
    - service: vacuum.send_command
      data:
          entity_id: vacuum.roomba
          command: start
          params:
            pmap_id: XXXYYYZZZ
            regions:
              - region_id: '9'
                type: rid
            user_pmapv_id: AAABBBCCC

But it fails when I use a variable for region_id. I think the Roomba expects region_id to be a string. My hard coded example works because the 9 is within single quotes:

region_id: '9'

I tried forcing the value to be a string using both methods below but neither worked:

region_id: "{{ region_id | string }}"

region_id: '"{{ region_id }}"'

Thoughts?

1 Like

Nope, I am still with this weird solution -.-

Thanks @klassm. I ended up using your same “0” trick. It is dumb, but it works! I appreciate you sharing it.

         - service: vacuum.send_command
            data:
              entity_id: vacuum.roomba
              command: start
              params:
                pmap_id: "{{ pmap_id }}"
                regions:
                  - region_id: "0{{ region_id | string }}"
                    type: "{{ type }}"
                user_pmapv_id: "{{ user_pmapv_id }}"
3 Likes