Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sthopeless/0382a0efd34ea6d19a00ca6406f3deab to your computer and use it in GitHub Desktop.
Save Sthopeless/0382a0efd34ea6d19a00ca6406f3deab to your computer and use it in GitHub Desktop.
EDP ASCII to Decimal
sensor:
- platform: template
sensors:
ascii_to_decimal:
friendly_name: "ascii_to_decimal"
value_template: >
{% set vals = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f" %}
{% macro ed(p) %}
{% if states('sensor.ascii_msg') | length == 3 -%} {{ ("%02X" % vals.index(states('sensor.ascii_msg')[0])) + ("%02X" % vals.index(states('sensor.ascii_msg')[1])) + ("%02X" % vals.index(states('sensor.ascii_msg')[2])) }}
{%- elif states('sensor.ascii_msg') | length == 2 -%} {{ ("%02X" % vals.index(states('sensor.ascii_msg')[0])) + ("%02X" % vals.index(states('sensor.ascii_msg')[1])) }}
{%- elif states('sensor.ascii_msg') | length == 1 -%} {{ ("%02X" % vals.index(states('sensor.ascii_msg')[0])) }}
{%- else -%} {{ states('sensor.ascii_msg') | length }}
{%- endif -%}
{% endmacro %}
{{ ed(p) | int(base=16) }}
#### FAKE SENSOR
- platform: mqtt
name: "ascii_msg"
state_topic: "EDP/fake/shit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment