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
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
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 …
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: