#Setting unique_id in an addon

1 messages · Page 1 of 1 (latest)

fluid aspen
#

I have also tried the following variations

#
{
"state":"164725",
"attributes":{
  "unique_id":"1486896602",
  "leak":"15",
  "leak_now":"3",
  "state_class":"total_increasing",
  "unit_of_measurement":"gal"
  }
}
#
{
"unique_id":"1486896602",
"state":"164725",
"attributes":{
  "leak":"15",
  "leak_now":"3",
  "state_class":"total_increasing",
  "unit_of_measurement":"gal"
  }
}
#
{
"unique_id":"1486896602",
"state":"164725",
"attributes":{
  "unique_id":"1486896602",
  "leak":"15",
  "leak_now":"3",
  "state_class":"total_increasing",
  "unit_of_measurement":"gal"
  }
}

and

{
"state":"164725",
"data":{
"unique_id":"1486896602"
},
"attributes":{
  "leak":"15",
  "leak_now":"3",
  "state_class":"total_increasing",
  "unit_of_measurement":"gal"
  }
}
#

Setting unique_id in an addon

hollow elk
#

@stoic wing is this something you know about ?
i tagged you since you helped me previously and my friend here is struggling

fluid aspen
#

It's interesting, I even did a search here on discord and except for my message "unique_id" doesn't even show up in this channel

hollow elk
fluid aspen
#

nope, been on that page, and the referenced developer docs page

hollow elk
#

pure latin to me so can't really help 😦

fluid aspen
#

one of the active parts of my code

function r900_parse {
  STATE="$(echo $line | jq -rc '.Message.Consumption' | tr -s ' ' '_')"
  LEAK="$(echo $line | jq -rc '.Message.Leak' | tr -s ' ' '_')"
  LEAKNOW="$(echo $line | jq -rc '.Message.LeakNow' | tr -s ' ' '_')"
  BACKFLOW="$(echo $line | jq -rc '.Message.BackFlow' | tr -s ' ' '_')"
  UNKN1="$(echo $line | jq -rc '.Message.Unkn1' | tr -s ' ' '_')"
  UNKN3="$(echo $line | jq -rc '.Message.Unkn3' | tr -s ' ' '_')"
  NOUSE="$(echo $line | jq -rc '.Message.NoUse' | tr -s ' ' '_')"
  RESTDATA=$( jq -nrc \
  --arg st "$STATE" \
  --arg le "$LEAK" \
  --arg ln "$LEAKNOW" \
  --arg uid "$DEVICEID-sdrmr" \
  --arg bf "$BACKFLOW" \
  --arg unkn1 "$UNKN1" \
  --arg unkn3 "$UNKN3" \
  --arg nouse "$NOUSE" \
  '{"state": $st, "extra_state_attributes": {"unique_id": $uid}, "attributes": { "entity_id": $uid, "state_class": "total_increasing", "unit_of_measurement": "gal", "leak": $le, "leak_now": $ln, "BackFlow": $bf, "NoUse": $nouse, "Unknown1": $unkn1, "Unknown3": $unkn3 }}')
}

r900_parse

echo -n "Sending  $RESTDATA  to http://supervisor/core/api/states/sensor.$DEVICEID -- "

curl -s -o /dev/null -w "%{http_code}" -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" \
  -H "Content-Type: application/json" \
  -d $RESTDATA \
  http://supervisor/core/api/states/sensor.$DEVICEID

echo -e "\n"
#

JSON from rtl_amr (formatted to look pretty)

{  
  "Time":"2022-04-30T01:29:28.13873522-04:00",
  "Offset":0,
  "Length":0,
  "Type":"R900",
  "Message":{
    "ID":1486896602,
    "Unkn1":161,
    "NoUse":0,
    "BackFlow":0,
    "Consumption":164725,
    "Unkn3":0,
    "Leak":15,
    "LeakNow":3
    }
}
hollow elk
#

where is $DEVICEID defined ?

fluid aspen
#

output

Sending  {"state":"164725","extra_state_attributes":{"unique_id":"1486896602-sdrmr"},"attributes":{"entity_id":"1486896602-sdrmr","state_class":"total_increasing","unit_of_measurement":"gal","leak":"15","leak_now":"3","BackFlow":"0","NoUse":"0","Unknown1":"161","Unknown3":"0"}}  to http://supervisor/core/api/states/sensor.1486896602 -- 200
fluid aspen
hollow elk
#

ok

fluid aspen
#

and equals 1486896602

hollow elk
#

same as unique_id

stoic wing
fluid aspen
#

sigh, Thats more info, but nothing that solves the issue, long sigh
I wish i knew a dev to ping

#

@boreal ore Sorry to ping you, I know it is really rude. You are the only mod I have talked with in the past, would you know who might be able to help me figure this out?

grave otter
#

I'm pretty sure the unique_id is part an entity registry entry. But the rest api only manipulates the state machine directly. It does not interact with the entity registry at all. That might well be a reasonable feature request, although I also know that the devs are reluctant to have an API that could replace integrations, as they don't want device manufacturers embedding hard-coded support for just home-assistant.

I think the "right way" to handle this is to have a seperate custom component, that interacts with your addon. Much like how the supervisor has the hassio component.

fluid aspen
#

I can't be the only one to run into this issue though. And I seriously don't consider the hack-around MQTT route to be an option, and those last 2 don't Make sense.

  1. why would they care if someone hard codes support for their program? its not like its a bad thing to support an open platform.
  2. I am not trying to make this as end-user friendly as possible. adding yet another thing people have to touch (aka the custom component) goes against that principle.

I wish, someone would be able to point a direction of a working example, or have any idea what's going on.

grave otter
#

And looking at the code to the rest api I am quite sure it does not provide entity registry access. Unless there is some second api that offers it, I think additional core development would be needed for such a scenario.

hollow elk
#

maybe something ?

in 2022.5.1 HA
Add unique ids to sensors (@shaiu - #71367) (sabnzbd docs)

#

@fluid aspen

fluid aspen
#

I'll have to take a look and see if sabnzbd is an integration.

#

It looks like it is. So it seems we are back to having to remake the project as an integration instead of an add-on

hollow elk
#

ok. i posted just in case it was a breakthru for you.....sad to hear it's not