Managing a 1-wire DS2408 relay board using OW-SERVER

I am re-implementing a verrrry old PHP/Linux/owfs system that controls my central heating to HA running on Docker a Pi4. I have an EDS OW_SERVER to run my 1-wire networks and an 8-channel relay board based around DS2408.

In Get sensor readings from OW-SERVER there were a mixture of approaches:

  • @larre suggested using a RESTful Sensor against the OW-SERVER’s CSV output, e.g. http owserver.local/gettag.csv?romid=FA0008022A1B3610&tag=Temperature&title=0
  • @bearfoo showed how to use the RESTful Sensor to pull DS18B20 temperature data using OW-SERVER’s XML output, e.g. http owserver.local/details.xml
  • David_Lindstrom suggested using OW-SERVER’s SNMP interface (also agreed with by EDS , i.e. Mr OW-SERVER :smile: )
  • Wuellueb suggested running a separate roobbb/owserver container and then connecting to it using the 1-wire Interface support built into HA

So I have two challenges:

  1. how to get the status of the 8 outputs (with bitwise operator to extract each channel from the output latch byte)
  2. how to update the DS2408 to change the output states

I have historically used a little bit of Python to set the state using this URL format http owserver.local/devices.htm?rom=MYDS2408ROM&variable=PIOOutputLatchState&value=128

For the first requirement, I really like the idea of making a call to details.xml and extracting all sensor data in one go - for me it seems fairly easy to understand and saves needing the SNMP MIB etc. However I’m not finding parsing the XML from HA easy to understand - it works a charm with @bearfoo 's example for DS18B20s but when I try to adapt that to owd_DS2408 it struggles to find the sensor data.

So I guess the first thing is whether using a REST Sensor is a good way to go, or maybe I start again with SNMP…? Then I’ll worry about the second requirement… :wink:

TIA!
Simon
PS. although I’m on a Pi I don’t want to move away from OW-SERVER as they are a nice way to abstract the vagaries of 1-wire, plus I’ve had a couple for a decade or more and they are super reliable.
PPS. as a new user I’m not allowed to mention more than 2 - thanks to contributions by others too!

My experimentation so far to extract the output from details.xml, without really understanding what I’m doing:

    - name: "Temp Fridge 3"
      unique_id: owserver2.temp.fdg3
      value_template: "{{ (value_json['Devices-Detail-Response']['owd_DS18B20'] | selectattr('ROMId','==','E1000002C8249328') | list | first)['Temperature']['#text'] | round(1) }}"
      force_update: true
      device_class: temperature
      unit_of_measurement: "°C"
      json_attributes_path: "$.['Devices-Detail-Response']['owd_DS18B20'][?(@.ROMId =='E1000002C8249328')]"
      json_attributes:
        - Channel
        - Health
        - ROMId
        - PowerSource

    - name: "Heating Control"
      unique_id: owserver2.control.hb8c
      value_template: "{{ (value_json['Devices-Detail-Response']['owd_DS2408'] | selectattr('ROMId','==','CF00000009A88829') | list | first)['PIOLogicState']['#text'] }}"
      force_update: true
      json_attributes_path: "$.['Devices-Detail-Response']['owd_DS2408'][?(@.ROMId =='CF00000009A88829')]"
      json_attributes:
        - PIOLogicState
        - Channel
        - Health
        - ROMId

The part of details.xml to be parsed is this:

<owd_DS2408 Description="8-Channel Addressable Switch">
<Name>DS2408</Name>
<Family>29</Family>
<ROMId>CF00000009A88829</ROMId>
<Health>7</Health>
<Channel>3</Channel>
<RawData>1919FF00008010104BFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</RawData>
<PrimaryValue>25</PrimaryValue>
<PIOLogicState>25</PIOLogicState>
<PIOOutputLatchState Writable="True">25</PIOOutputLatchState>
<PIOActivityLatchState Writable="True">255</PIOActivityLatchState>
<RSTZconfiguration Writable="True">0</RSTZconfiguration>
<PowerOnResetLatch Writable="True">0</PowerOnResetLatch>
<VccPowerStatus>1</VccPowerStatus>
</owd_DS2408>

which looks almost identical to the temperature section:

<owd_DS18B20 Description="Programmable resolution thermometer">
<Name>DS18B20</Name>
<Family>28</Family>
<ROMId>E1000002C8249328</ROMId>
<Health>6</Health>
<Channel>1</Channel>
<RawData>4B004B467FFF0510DCFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</RawData>
<PrimaryValue>4.6875 Deg C</PrimaryValue>
<Temperature Units="Centigrade">4.6875</Temperature>
<UserByte1 Writable="True">75</UserByte1>
<UserByte2 Writable="True">70</UserByte2>
<Resolution>12</Resolution>
<PowerSource>255</PowerSource>
</owd_DS18B20>

The temperature works perfectly, but the the DS2408 sensor is showing as Unknown and in the log I get homeassistant.components.rest.util JSON result was not a dictionary or list with 0th element a dictionary.

I’ve checked the IDs and syntax very carefully but I think my main problem is I don’t understand how HA is managing to parse the XML as if it’s JSON… :thinking:

I’ve found a handful of topics where people have been trying to parse XML from a RESTful Sensor, though mostly seem to end up doing pattern matching (which sounds like very hard work).

RESTful Sensor json_attributes doc says:

A list of keys to extract values from a JSON dictionary result and then set as sensor attributes. If the endpoint returns XML with the text/xml, application/xml or application/xhtml+xml content type, it will automatically be converted to JSON according to this specification

So it feels like I should be able to extract whatever I need from the OW-SERVER’s details.xml just the syntax is a little tricky.

PS. OW-SERVER is such a good product (prior to that I used to spend ages faffing around with 1-wire adapters & owfs) it would be great if one day @EDS has chance include a REST API… probably harder work than it sounds though…

Hi Simon,

It seems that @bearfoo 's example works when there are multiple of a specific type of sensor connected to the OW-SERVER. This gets the sensor type structured in an array. I’d expect the following to work if you have multiple DS2408s connected to the OW-SERVER:

  - name: "Heating Control"
    unique_id: owserver1.control.hb8c
    `value_template: "{{ (value_json['Devices-Detail-Response']['owd_DS2408'] | selectattr('ROMId','==','CF00000009A88829') | list | first)['PIOLogicState'] }}"`
    force_update: true
    json_attributes_path: "$.['Devices-Detail-Response']['owd_DS2408'][?(@.ROMId =='CF00000009A88829')]"
    json_attributes:
      - Channel
      - Health
      - ROMId

I’d suggest trying the following if you only have one DS2408:

  - name: "Heating Control"
    unique_id: owserver1.control.hb8c
    value_template: "{{ (value_json['Devices-Detail-Response']['owd_DS2408']['PIOLogicState']) }}"
    force_update: true
    json_attributes_path: "$.Devices-Detail-Response[owd_DS2408]"
    json_attributes:
      - Channel
      - Health
      - ROMId

Please let me know the results.

Thanks @EDS :slight_smile: . I have been a bit distracted with work and realised I’d forgotten this.

I did getting it working (just one DS2408 connected) with this:

- name: "Heating Control Kitchen"
  unique_id: owserver2.control.hbc1
  value_template: "{{ value_json['Devices-Detail-Response']['owd_DS2408']['PIOLogicState'] | int | bitwise_and(0b00000010) == 0 }}"
  force_update: true
  json_attributes_path: "$.['Devices-Detail-Response']['owd_DS2408']"
  json_attributes:
    - Channel
    - Health
    - ROMId

However, previously I couldn’t get my version which included the ROM ID to work (which could be useful since I have a backup HobbyBoards DS2408). Looking at one of my temperature sensors I’m pretty sure I was trying very similar permutations to yours, but I was getting some weird behaviour as if it was treating all devices, including the DS2408, like an owd_DS18B20.

More urgent is to get HomeAssistant to have a button to send a devices.htm?rom=CF00000009A88829&variable=PIOOutputLatchState&value=113 etc to OWSERVER as I’m currently having to do a binary to decimal conversion to control my heating :rofl:

Anyway, unfortunately I seem to have paged out the useful information so will have to try to get it back in my head at the weekend!

I’ve used the following RESTful Commands to change the state of a DS18B20’s UserByte1. It should be usable with the obvious substitutions (IP Address, ROM, Variable, and Value).

rest_command:
  hvac_off:
    url: "http://10.0.10.138/devices.htm?rom=7200000E36D9C528&variable=UserByte1&value=85"
    method: get
  hvac_on:
    url: "http://10.0.10.138/devices.htm?rom=7200000E36D9C528&variable=UserByte1&value=0"
    method: get

You can then select the command in the Automation’s Visual Editor by navigating to Add Action>Other actions>RESTful Command. From there, you’ll have the option of selecting which command (and therefore URL) to be sent. The options are “hvac_off” and “hvac_on” in my example.

1 Like

Thanks @EDS - the rest_command, plus Helper entity button, works a charm! Now I’ve got the basic on/off working I’ll try to add some more sophistication so the user can see the button has been pressed already but it’s still waiting for HA & then OWSERVER to change the state of the DS2408.