The reason I need the number without decimal is because the input_number will be exposed to the knx bus. And the knx is validating the number and will fail with decimals.
Is there a way to do this?
Thank you very much for your help. Best regards
but the error i get is:
(I know its just because of the decimal, because i also created a input_text with string value 700 and this works -> but it’s ugly i think )
Logger: homeassistant.core
Source: components/knx/__init__.py:400
First occurred: 20:23:43 (1 occurrences)
Last logged: 20:23:43
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/xknx/dpt/dpt_2byte_uint.py", line 33, in to_knx
knx_value = int(value)
ValueError: invalid literal for int() with base 10: '700.0'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/knx/__init__.py", line 385, in _async_entity_changed
await self._async_set_knx_value(new_state.state)
File "/usr/src/homeassistant/homeassistant/components/knx/__init__.py", line 400, in _async_set_knx_value
await self.device.set(value)
File "/usr/local/lib/python3.7/site-packages/xknx/devices/expose_sensor.py", line 74, in set
await self.sensor_value.set(value)
File "/usr/local/lib/python3.7/site-packages/xknx/remote_value/remote_value.py", line 120, in set
payload = self.to_knx(value) # pylint: disable=assignment-from-no-return
File "/usr/local/lib/python3.7/site-packages/xknx/remote_value/remote_value_sensor.py", line 230, in to_knx
return DPTArray(self.DPTMAP[self.value_type].to_knx(value))
File "/usr/local/lib/python3.7/site-packages/xknx/dpt/dpt_2byte_uint.py", line 38, in to_knx
raise ConversionError("Cant serialize %s" % cls.__name__, value=value)
xknx.exceptions.exception.ConversionError: <ConversionError description="Cant serialize DPTTimePeriodSec" value="700.0"/>
It works perfect -> Thank you very much for your help. I didn’t expect such a fast answer.
To be honest i don’t understand what the |int is doing. Is it convertign to a integer?
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/xknx/dpt/dpt_2byte_uint.py", line 33, in to_knx
knx_value = int(value)
ValueError: invalid literal for int() with base 10: '700.0'
That’s using Python’s int (integer) type to convert a string to an integer. Unfortunately that doesn’t work with a string containing a decimal (i.e., a string representation of a float.)
But the |int part in the Jinja template is a filter, specifically the int filter. It does pretty much the same as the Python function, but it can accept a string representation of a float. (Remember, all states in HA are strings.)
This seems odd that an INPUT_NUMBER set to STEP: 1 would display a .0 by default - seems it should reference the STEP when displayed. Realize you can create template sensor for it - but this seems duplicative.