JuelDK
April 18, 2023, 5:04pm
1
Hi guys
I have passed a sensor from HA to my ESP home, it works fine, it shows up in the esp32 logs as expected. But when I try to use the value in my esp32, i get this fault:
Expected integer, but cannot parse id(“sdm_630_address0”).state as an integer.
It’s defined as an Int in HA.
This is the import:
- platform: homeassistant
name: "sdm-630-address0"
entity_id: sensor.sdm630address0
id: "sdm_630_address0"
This i where I try to use it:
modbus_server:
- id: modbuserver
uart_id: smartmetersim
address: 2 # slave address
holding_registers:
- start_address: 0
default: id("sdm_630_address0").state # default value of register
number: 1
on_read: return value;
I have also tried without .state and with ->state but same result.
Can anyone point me in the right direction? Thanks
Is your sensor defined under sensor:
and not text_sensor
or other type?
Alternatively, if I have trouble trying to see what the sensor type? is, I use logging.
- interval: 30s
then:
- logger.log:
format: "sdm-630-address0 : %i"
args: [ 'id(sdm_630_address0)' ]
If %i
doesn’t work, try %.0f
(for float) %s
(for text).
I’m sure there is a better way, but this should work.
Also it might be that you are using double quotes … I’m reasonable sure that you don’t need them in the ‘setup’ part and only single quotes in the other part
1 Like
JuelDK
April 18, 2023, 6:49pm
3
It was under text-sensor, but i have now moved it to sensor:
- platform: homeassistant
name: "sdm-630-address0"
entity_id: sensor.sdm630address0
id: sdm_630_address0
And
modbus_server:
- id: modbuserver
uart_id: smartmetersim
address: 2 # slave address
holding_registers:
- start_address: 0
default: int(id("sdm_630_address0").state) # default value of register
number: 1
on_read: return value;
Still makes the same error,
default: id(“sdm_630_address0”).state is also tried.
If I paste your code under logging like this:
logger:
level: VERBOSE #makes uart stream available in esphome logstream
baud_rate: 0 #disable logging over uart
- interval: 30s
then:
- logger.log:
format: "sdm-630-address0 : %i"
args: [ 'id(sdm_630_address0)' ]
I just get logging errors because im using uart.
modbus_server:
- id: modbuserver
uart_id: smartmetersim
address: 2 # slave address
holding_registers:
- start_address: 0
default: int(id('sdm_630_address0'.state)) # default value of register
number: 1
on_read: return value;
All I changed there was the " to ’ , oh, I also moved a bracket.
I use (int)id(some_sensor)
although, both may work
I’m no expert btw, did I mention that?
interval:
- interval: 1min
Interval doesn’t go under logger: it is it’s own component (but like you say you are using uart so it won’t work)
JuelDK
April 18, 2023, 7:29pm
5
That didn’t work either, but the interval log gives this:
[21:20:24][D][main:261]: sdm-630-address0 : 1073429584
Without the interval inserted I get this:
[21:30:24][D][text_sensor:067]: 'sdm-630-address0': Sending state '231'
Which makes no sense to me, and no worries, I take all the input I can get, I’m new in this field
Yeah, I don’t know … but when you work it out, don’t forget to come back and let the rest of us know what you did
Could it expect hex input perhaps? Just guessing.
JuelDK
April 18, 2023, 9:13pm
8
Maybe, but it won’t solve my initial problem
1 Like
Seems you need to start with !lambda
in order to reference id’s.
Kimotu
(Kimotu Bates)
April 19, 2023, 8:25pm
11
Can you try this?
default: !lambda return id('sdm_630_address0').state;
JuelDK
April 21, 2023, 7:03pm
13
modbus_server:
- id: modbuserver
uart_id: smartmetersim
address: 2 # slave address
holding_registers:
- start_address: 0
default: !lambda return id('sdm_630_address0').state;
number: 1
on_read: return value;
Just gives me this error: “This option is not templatable!.”
Kimotu
(Kimotu Bates)
April 21, 2023, 7:58pm
14
This means you cannot dynamically set a value for default
and have to set a fixed, static value.
2 Likes
pongo
(Gianfranco)
May 15, 2023, 8:08pm
15
Try with:
modbus_server:
- id: modbuserver
uart_id: smartmetersim
address: 2 # slave address
holding_registers:
- start_address: 0
default: 1
number: 1
on_read: |
return int(id('sdm_630_address0').state);