I have a device sending data to home assistant over serial port:
sensor:
- platform: serial
serial_port: /dev/ttyUSB0
baudrate: 9600
stopbits: 1
name: veeder
Under “Developer Tools - Events” I’m listening to “state-changed”, when I request data from my device, I get this returned to me:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "1 TEST TANK 8178 71.35 1.2 70.4 1550",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.369028+00:00",
"last_updated": "2021-01-30T03:23:00.369028+00:00",
"context": {
"id": "5f2237a3f3ce6e21564edc58c83edbb0",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.529468+00:00",
"last_updated": "2021-01-30T03:23:00.529468+00:00",
"context": {
"id": "316eb114345fe625d8f9f9ddbd4942ac",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.529468+00:00",
"context": {
"id": "316eb114345fe625d8f9f9ddbd4942ac",
"parent_id": null,
"user_id": null
}
}
Event 8 fired 8:23 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.289744+00:00",
"last_updated": "2021-01-30T03:23:00.289744+00:00",
"context": {
"id": "4d7340ffb8aaf08fcd1fbd6b2fc0df85",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "1 TEST TANK 8178 71.35 1.2 70.4 1550",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.369028+00:00",
"last_updated": "2021-01-30T03:23:00.369028+00:00",
"context": {
"id": "5f2237a3f3ce6e21564edc58c83edbb0",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.369028+00:00",
"context": {
"id": "5f2237a3f3ce6e21564edc58c83edbb0",
"parent_id": null,
"user_id": null
}
}
Event 7 fired 8:23 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "TANK PRODUCT GALLONS INCHES WATER DEG F ULLAGE",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.288668+00:00",
"last_updated": "2021-01-30T03:23:00.288668+00:00",
"context": {
"id": "bf4f936081e0122ba010991ff6465624",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.289744+00:00",
"last_updated": "2021-01-30T03:23:00.289744+00:00",
"context": {
"id": "4d7340ffb8aaf08fcd1fbd6b2fc0df85",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.289744+00:00",
"context": {
"id": "4d7340ffb8aaf08fcd1fbd6b2fc0df85",
"parent_id": null,
"user_id": null
}
}
Event 6 fired 8:23 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.225561+00:00",
"last_updated": "2021-01-30T03:23:00.225561+00:00",
"context": {
"id": "2bf95ef3a3b22dc46ead9ae26b437aa9",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "TANK PRODUCT GALLONS INCHES WATER DEG F ULLAGE",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.288668+00:00",
"last_updated": "2021-01-30T03:23:00.288668+00:00",
"context": {
"id": "bf4f936081e0122ba010991ff6465624",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.288668+00:00",
"context": {
"id": "bf4f936081e0122ba010991ff6465624",
"parent_id": null,
"user_id": null
}
}
Event 5 fired 8:23 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "01-27-21 20:23",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.209392+00:00",
"last_updated": "2021-01-30T03:23:00.209392+00:00",
"context": {
"id": "65eee56f21a91c0ba8e1fd774258c35f",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.225561+00:00",
"last_updated": "2021-01-30T03:23:00.225561+00:00",
"context": {
"id": "2bf95ef3a3b22dc46ead9ae26b437aa9",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.225561+00:00",
"context": {
"id": "2bf95ef3a3b22dc46ead9ae26b437aa9",
"parent_id": null,
"user_id": null
}
}
Event 4 fired 8:23 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.193635+00:00",
"last_updated": "2021-01-30T03:23:00.193635+00:00",
"context": {
"id": "eb55b1945872178d918ac5a557d4ec12",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "01-27-21 20:23",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.209392+00:00",
"last_updated": "2021-01-30T03:23:00.209392+00:00",
"context": {
"id": "65eee56f21a91c0ba8e1fd774258c35f",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.209392+00:00",
"context": {
"id": "65eee56f21a91c0ba8e1fd774258c35f",
"parent_id": null,
"user_id": null
}
}
Event 3 fired 8:23 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "TEST STATION",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.192664+00:00",
"last_updated": "2021-01-30T03:23:00.192664+00:00",
"context": {
"id": "cf83bb09697d0a8c1d33b3745386d66a",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.193635+00:00",
"last_updated": "2021-01-30T03:23:00.193635+00:00",
"context": {
"id": "eb55b1945872178d918ac5a557d4ec12",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.193635+00:00",
"context": {
"id": "eb55b1945872178d918ac5a557d4ec12",
"parent_id": null,
"user_id": null
}
}
Event 2 fired 8:23 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "201",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.081910+00:00",
"last_updated": "2021-01-30T03:23:00.081910+00:00",
"context": {
"id": "eb42ca2403b820551adc613bc3ec0681",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "TEST STATION",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.192664+00:00",
"last_updated": "2021-01-30T03:23:00.192664+00:00",
"context": {
"id": "cf83bb09697d0a8c1d33b3745386d66a",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.192664+00:00",
"context": {
"id": "cf83bb09697d0a8c1d33b3745386d66a",
"parent_id": null,
"user_id": null
}
}
Event 1 fired 8:23 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "\u0001",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.081002+00:00",
"last_updated": "2021-01-30T03:23:00.081002+00:00",
"context": {
"id": "5bf668102035c92a64a52910a545a086",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "201",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.081910+00:00",
"last_updated": "2021-01-30T03:23:00.081910+00:00",
"context": {
"id": "eb42ca2403b820551adc613bc3ec0681",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.081910+00:00",
"context": {
"id": "eb42ca2403b820551adc613bc3ec0681",
"parent_id": null,
"user_id": null
}
}
Event 0 fired 8:23 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "sensor.veeder",
"old_state": {
"entity_id": "sensor.veeder",
"state": "unknown",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:22:14.331274+00:00",
"last_updated": "2021-01-30T03:22:14.331274+00:00",
"context": {
"id": "43cfe14f3419d72b354d6496142706ed",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "sensor.veeder",
"state": "\u0001",
"attributes": {
"friendly_name": "veeder"
},
"last_changed": "2021-01-30T03:23:00.081002+00:00",
"last_updated": "2021-01-30T03:23:00.081002+00:00",
"context": {
"id": "5bf668102035c92a64a52910a545a086",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2021-01-30T03:23:00.081002+00:00",
"context": {
"id": "5bf668102035c92a64a52910a545a086",
"parent_id": null,
"user_id": null
}
}
When I look at the sensor on “overview” lovelace, I see the states changing rapidly and I see my data there for a split second. I have been trying to figure out how to make a template to parse this part in particular and make 5 different sensors with it.
"state": "1 TEST TANK 8178 71.35 1.2 70.4 1550",
I have spent weeks trying so many different value_templates things, I can’t get anything to work!
This is the closest I have gotten to anything.
sensor:
- platform: serial
serial_port: /dev/ttyUSB0
baudrate: 9600
stopbits: 1
name: veeder
value_template: >
{{ states('sensor.veeder').split(' ')[3] }}
- platform: template
sensors:
time_1_mode:
friendly_name: Timer 1 Mode
value_template: >
{% if states("sensor.veeder") == "TEST" %}
{{ states("sensor.veeder") }}
{% endif %}