How to read RESTful sensor-data from another Hass.io instance on the same network?

Hello, new Home Assistant user here. First of all, thanks to the whole community for maintaining such a brilliant home automation platform!

Then to my problem:

I’m running hass.io on Raspberry Pi 3+ on two different setups (connected on the same LAN), and I’d like to read input_select / sensor data with the 1st RPi from the 2nd RPi. I’ve tried to accomplish this first via mqtt, and now with REST API / RESTful Sensor. I had to convert my “input_select” to “sensor” (both outputting states: S1/S2/S3/S4), because I couldn’t figure out how to create “REST input select”

This is my sensor.yaml configuration:

  - platform: rest
    resource: http://xxxxxxxx:8123/api/states/sensor.mysensor
    method: POST
    name: Mysensor REST
    payload: '{{ value_json.state }}'
    headers:
      Authorization: !secret token

This is the error I’m getting:
{“message”: “Invalid JSON specified.”}

Sensor State should read S1, S2, S3 or S4.

I couldn’t find proper instructions how to configure RESTful sensor, but according to my understanding I need to configure POST method for exposing the sensor, and GET method for the 2nd RPi to read it. Am I correct here?

Thanks for any help.

Reply to my own thread, I got it working!
My solution was to directly control switch/input_boolean on the remote hassio instance, and not trying to read primary hassio sensors with the remote hassio.

So for anyone puzzling with similar setup, here’s my solution:

  1. Create “Long-Lived Access Token” on the remote RPi, the one which has the switches etc. you want to control remotely. You’ll find this token-menu when you click your username one the lower left corner.

  2. Create rest_command

rest_command:
  my_rest_command:
    url: http://(IP_OF_YOUR_2ND_RPI):8123/api/states/ENTITY_NAME_ON_2ND_RPI (e.g. input_boolean.my_switch)
    method: POST
    headers: 
      Authorization: Bearer YOUR_TOKEN_FROM_2ND_RPI
      content-type: 'application/json'
    payload: '{"state":"{{states.ENTITY_NAME_ON_1ST_RPI.state}}"}'
  1. Create automation to trigger your ‘rest_command’ when the input_boolean state changes.
automation:
  - alias: 'my remote automation'
    hide_entity: True
    initial_state: On
    trigger:
      - platform: state
        entity_id: input_boolean.my_switch
    action:
      - service: rest_command.my_rest_command

How it works:
You control e.g. some input_boolean on your main Hass.io instance, (ENTITY_NAME_ON_1ST_RPI) and that action gets cloned to another entity (ENTITY_NAME_ON_2ND_RPI) on the remote Hass.io instance. Change everything written in capital letters (except ‘method POST’) according to your setup.

2 Likes