Posting Temperature Sensor data via REST to Word Press?

I have setup a self-hosted word press page, and using postman I can create/edit a post.

What I want to do is create an automation to publish the temperature of my pool as an update to this post, so theres essentially one post on the page that is updated with the latest temperature.

I can use postman to get the temperature data with url/api/states/sensnor.pool_temp

Im just confused with how to create the command in HA to post this data to Word Press, using the rest API I have for updating a topic, IM using username and application password, just not sure how to get the json values and how to put everything into the yaml, this type of stuff is not ym strong point, and the examples I’ve seen arent adding up for me, can anyone chime in?

Have a look at rest_command. This lets you define a url that you want to send data to, and payload which contains the data in the format that the receiving end understands. The payload itself can be a template which means you can include data from a temperature sensor.
Once defined, you can use your new rest_command in an automation that is for example triggered every time the temperature sensor changes or at regular intervals.

I’ve used REST commands for doing things like launching apps on my fully kiosk tablet. in my config entry, am I just trying to set up the REST command with an essentially blank payload, and then use my automation to fill in the data for the payload? I’m not good with templating, all of my templates are from examples, lol.

  wp_publish:
    url: WP REST URL HIDDEN
    method: POST
    headers:
      username: sean
      password: hidden
    content_type:  'application/json; charset=utf-8'
    payload: '{"status":{"status_text": "{{ status }}","content": "{{ content }}"}}'

I have a sonoff basic flashed with tasmoto on my pool pump, I connected 2 DS182 temp probes to it, one goes to the pool, the other is in a 3d-printed stevenson screen for outside air temp. so the entity name of the pool is sensor.pool_temp I think I need to template out the ‘state’ of the thermometer entity, but do I do that in the config entry, or in the automation?

This is the body I use in Post Man for testing posting content via REST API, this was just done to make sure my rest commands are actualyl posting before trying to implement into HA.

{
    "status": "publish",
    "content": "Temperature 2"
}

ok im getting somewhere now, in dev tools, when I call service Im getting a 401 for bad auth, but Im using the same credentials in postman and it works, so maybe my syntax in my config entry is bad and its not passing the user/pass correctly?

  wp_publish:
    url: https://pool.seanvoets.com/wp-json/wp/v2/posts/28
    method: POST
    headers:
      username: homeassistant
      password: application-password-from-wp
    payload: '{"status": "{{status}}":,"content": "{{ content }}"'

No longer getting errors, which makes me think its making it out to WP, but im not seeing the post update, in developer, this is what I have to call the service:

service: rest_command.wp_publish
data: {
          status: publish
          content: home assistant test
}

This would send username and password as request headers which probably doesn’t work with Wordpress. Are you sure that in Postman you are defining username and passwords as headers?

If you are using a Wordpress basc authentication plug-in, then username and password need to be unindented, i.e. at the same indentation level as url and method.

Otherwise I think you are on the right path.

yes, I have moved the authentication out fo the headers, the problem now it with my syntax in the payload.

Ideally, I would like the service to be generic, and I can fill in the “data” portion when doing my automation for whichever data I want to send.

Right now Im not even tyring to send sensor data, I’m just trying to use the service in dev tools to make a post from HA, then Ill start dicking around with how to template out the sensors, but I’m stuck:

wp_publish_pool_temp:
    url: WP REST url
    method: POST
    username: homeassistant
    password: lapp_password
    content_type:  'application/json; charset=utf-8'
    payload: "status": "publish", "content": "this is a test from HA"

Im using the sqame syntax for the body that I use when doing postman, but it returns error 400, which is syntax, so obviously im not handling the payload correctly.

That probably won’t work because of the quotes. I think you were on the right path previously. Can you generate a static JSON payload in the first instance, just to make sure that connectivity works? So, something like:

  payload: "{ 'status': 'publish', 'content': 'Temperature 2' }"

Once that works, you can go back to using templates and make this more generic.

OK so I used your example, and last night I installed an API logger on my WP site, I can see the posts hitting WP, but not updating. I’m just confused because I can make it work in postman but not HA.

Heres the log from HA

Error. Url: https://pool.seanvoets.com/wp-json/wp/v2/posts/38. Status code 400. Payload: b"{ 'status': 'publish', 'content': 'Temperature 2' }"
10:12:22 AM – (WARNING) RESTful Command

Heres the log from WP:

{
    "data": {
        "code": "rest_invalid_json",
        "message": "Invalid JSON body passed.",
        "data": {
            "status": 400,
            "json_error_code": 4,
            "json_error_message": "Syntax error"
        }
    },
    "headers": {
        "Allow": "GET, POST, PUT, PATCH, DELETE"
    },
    "status": 400
}

In the developer tools for call service, theres the field in YAML mode for inputting data, can I not put a payload field in the config entry and then just fill in the data field?

Not sure what to do regarding getting the syntax right to get it over to WP, this is jsut for text havent even tried getting sensor json

Sorry, can’t really help you much. I just tried updating a Wordpress post using curl and I can make that work if the payload is not JSON but simply key-value-pairs, e.g. title=New Title, but I can’t do the same using Postman. When I tried using any kind of JSON payload with curl, it doesn’t do anything.
If using Postman works for you then you may need to compare all request headers with what Home Assistant sends across. It wouldn’t surprise me if Postman is sending a request header indicating that it sends a JSON payload, but in Home Assistant you may need to explicitly set that header.

Its weird, because the “content” in my data field of the service shows up in WP as the “slug”
I’ve added the following to my entry:

headers:
      accept: "application/json, text/html"
      content-type: application/json