mrk-its / can2mqtt

Apache License 2.0
44 stars 5 forks source link

Number component doesn't work properly in HA #10

Open timota opened 1 year ago

timota commented 1 year ago

Number component doesn't work properly in HA. Due to scale up/down feature, number in gui more or less from original number provided by canopen node.

Example:

CO Node:

sprinkler: 
        ...
       # number component
        run_duration_number:
          id: ctrlr_z2_run_duration_number
          name: 'Zone#2 Duration'
          unit_of_measurement: min
          restore_value: true
          initial_value: 1
          max_value: 30
          mode: box

   # co configuration
   ...
    - id: ctrlr_z2_run_duration_number
      index: 6
      tpdo: 2
      size: 1
      min_value: 1
      max_value: 30
      rpdo:
        - node_id: ${can_client_id}
          tpdo: 2
          offset: 1

when number set to 6 on node, it appears as 5 in GUI, 30->29 I guess this is something with rounding numbers.

Also, according to documentation, (https://www.home-assistant.io/integrations/number.mqtt/) autodiscovery mqtt message should should be presented as min and max (currenly min_value, and max_value ) to make it work properly in GUI

{
"object_id": "can_00b_06", 
"entity_id": "can_00b_06", 
"unique_id": "can_00b_06", 
"availability": [
    {
       "topic": "homeassistant/can_00b/availability"
    }, 
    {
      "topic": "homeassistant/can2mqtt/status"
    }
], 
"availability_mode": "all",
"device": {
    "identifiers": ["canopen_node_11"], 
    "name": "can-slave-3", 
    "sw_version": "", 
    "hw_version": "", 
    "manufacturer": "mrk", 
    "model": "esphome-canopen"
}, 
"name": "Zone#2 Duration", 
"min_value": 1.0, 
"max_value": 30.0, 
"command_topic": "homeassistant/can_cmd_00b_20620100", 
"state_topic": "homeassistant/can_state_00b_20610100"
}
mrk-its commented 1 year ago

Ok, will try to reproduce it.

In the meantime try to remove min_value & max_value from co configuration (for single byte it will default to 0-255)

timota commented 1 year ago

will try, but if you can add min/max to autodiscovery - it will fix part of issue with gui. Values wont overflow as default (1/100)