Hi guys,
I have an esp-home device with a CAN-bus controller connected.
I currently use this to read data from my heat pump.
For some basic data I already know the correct commands to receive a nice answer and hardcode the CAN-bus command in the ESPhome device like this:
- canbus.send:
data: [ 0x31, 0x00, 0xfa,0x09,0x28,0x00,0x00 ]
can_id: 0x680
- delay: 500ms
I can also read any answers from the pump with the following code
- can_id: 0x180
then:
- lambda: |-
int val0 = int(x[0]);
int val1 =int(x[1]);
int val2 =int(x[2]);
int val3 =int(x[3]);
int val4 =int(x[4]);
int val5 =int(x[5]);
int val6 =int(x[6]);
ESP_LOGI("main", "answer from 180 hex: %x %x %x %x %x %x %x", val0, val1, val2, val3, val4, val5, val6);
Now for troubleshooting, if I want to send commands dynamically to change parameters in the heat pump or read other data from it. I want to send commands from an home assistant input_text field and see what’s happening in the log.
I created an home assistant input_text in the config.yaml:
input_text:
dynamic_input:
name: dynamic_input1
initial: default
and in ESP-home I already can receive the content and print it in the log, using this:
text_sensor:
- platform: homeassistant
name: "dynamic_input1"
entity_id: input_text.dynamic_input1
id: HASSinput
switch:
- platform: template
name: "print dynamic_input1"
id: p_input
turn_on_action:
lambda: |-
std::string val = to_string(id(HASSinput).state);
ESP_LOGI("main", "Value of my sensor: %s", val.c_str());
turn_off_action:
- delay: 500 ms
This prints the input of my home assistant sensor in the log of the ESP-home device, every time the switch is activated in home assistant.
But how can I convert an input string like “0x31,0x00,0xfa,0x09,0x2a,0x00,0x00” or “\x31\x00\xfa\x09\x2a\x00\x00” into code that can be sent over the can-bus as typed in?